第一个应用程序 - 在startActivity上崩溃

时间:2011-12-17 18:24:57

标签: android

我对Android很新,并且有一段简单的代码,其中有一些按钮,当点击一个按钮时,它会打开下一个屏幕正确(PriceScreen),但是当点击另一个时,(LocationScreen)在行startActivity上崩溃( viewlocationScreen);

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);作为结束而不是..它的工作原理。 谁能告诉我为什么?

提前致谢 贝

1 个答案:

答案 0 :(得分:0)

您是否在清单文件中注册了第二项活动? 如果您也可以发布清单文件,那么在诊断问题时会有所帮助。

应用程序中使用的所有活动必须在清单文件中有一个条目,以便android实际启动它们。

不需要在启动器中显示的其他活动可以在这样的清单文件中注册(来自我目前正在处理的应用程序)

<activity
    android:label="@string/app_name"
    android:name=".LineupActivity">
</activity>

示例中的“.LineupActivity”替换为您的活动的类名称。在您的情况下.LocationScreen

相关问题