我对Android非常陌生,并且有一段简单的代码,它有一些按钮,当点击它时会打开正确的下一个屏幕(PriceScreen),但当另一个点击时(LocationScreen)在线startActivity(viewlocationScreen);崩溃第一个应用程序 - 在startActivity上崩溃
LocationScreen.java和PriceScreen.java的代码“似乎”是完全一致的。 代码调用它是
public class TaxiAppActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button bBtnYes = (Button) findViewById(R.id.btnYes);
bBtnYes.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent viewLocationScreen = new Intent(TaxiAppActivity.this,LocationScreen.class);
// Intent viewLocationScreen = new Intent(TaxiAppActivity.this,PriceScreen.class);
startActivity(viewLocationScreen); // << error here
}
});
Button cBtnGetPrice = (Button) findViewById(R.id.btnGetPrices);
cBtnGetPrice.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
Intent viewPriceScreen = new Intent(TaxiAppActivity.this,PriceScreen.class);
startActivity(viewPriceScreen);
}
});
// super.onCreate(savedInstanceState);
}
在上面的代码,如果我注释掉线
Intent viewLocationScreen = new Intent(TaxiAppActivity.this,LocationScreen.class);
并使用.... PriceScreen.class);作为结束,而不是..它的工作原理。 谁能告诉我为什么?
在此先感谢 托尼
您是否已将“LocationScreen”活动添加到清单中? – Dalmas 2011-12-17 18:29:55
“谁能告诉我为什么?” - 只是猜测,但你还没有在你的'AndroidManifest.xml'中声明'LocationScreen'为''?如果这不是答案,那么发布logcat输出。 –
Squonk
2011-12-17 18:31:28
欢迎来到SO。当试图解决Java/Android中的崩溃问题时,最好将堆栈跟踪添加异常详细信息,这样,没有人需要猜测太多,并且帮助您更容易。 – MByD 2011-12-17 18:32:41