5

我已经在这几个小时了,无法弄清楚。当我调试时,它给出了上述错误。我是新手,所以如果很明显我错过了什么,请保持温和...

这是从第一个活动中引入崩溃的代码,它仍然标记为“主要”:

//-- Menu Press --

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

//-- Handle item selection
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.menu_settings:
            Intent menu = new Intent(this, Menu.class);
            menu.putExtra("plWin", plWin);
            menu.putExtra("plLoss", plLoss);
            menu.putExtra("plDraw", plDraw);
            startActivity(menu);
            return true;
        case R.id.menu_reset:
            if (opCounter > plCounter) {
                plLoss++;
            }else if (opCounter < plCounter) {
                plWin++;
            }else {
                plDraw++;
            }
            opCounter = 0;
            plCounter = 0;
            return true;
        default:
            return false;
    }

}

第二个活动,当前名为“菜单”:

public class Menu extends Activity {

Intent menu = getIntent();
int wins = menu.getIntExtra("plWin", 0);
int losses = menu.getIntExtra("plLoss", 0);
int draws = menu.getIntExtra("plDraw", 0);

private TextView winNum = null;
private TextView lossNum = null;
private TextView drawNum = null;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);


    //-- Win Counter --
    LinearLayout winView = (LinearLayout) findViewById(R.id.plLeft);
    winNum = (TextView) winView.findViewById(R.id.winNum);
    winNum.setText("" + wins);

    //-- loss Counter --
    LinearLayout lossView = (LinearLayout) findViewById(R.id.plMid);
    lossNum = (TextView) lossView.findViewById(R.id.lossNum);
    lossNum.setText("" + losses);

    //-- Draw Counter --
    LinearLayout drawView = (LinearLayout) findViewById(R.id.plRight);
    drawNum = (TextView) drawView.findViewById(R.id.drawNum);
    drawNum.setText("" + draws);
}

public void onBackPressed() {
    finish();
    super.onBackPressed();
}

}

这是我的清单:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sesto.life.counter"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="15" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Main"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity 
        android:name="com.sesto.life.counter.Menu"
        android:label="@string/title_activity_menu" >

    </activity>  

</application>

我正在寻找想法。谢谢大家

4

3 回答 3

12

我只看到一个可能的错误是 at Intent menu = new Intent(this, Menu.class); 。请检查Menu.class是您的Menu class但不是Android Menu View(位于android.view.Menu)。logcat 告诉它android.view.Menumanifest. 将鼠标指针悬停在上方Menu.class以检查您为此导入了哪个类。

于 2012-09-01T03:10:14.733 回答
2

改变

<activity 
        android:name="com.sesto.life.counter.Menu"
        android:label="@string/title_activity_menu" >

</activity>  

<activity 
    android:name=".Menu"
    android:label="@string/title_activity_menu" >

</activity>  

看看是否有帮助

于 2012-09-01T02:09:21.417 回答
1

当我忘记在清单文件中添加活动时收到此错误消息。

于 2016-06-28T09:46:27.237 回答