Android错误“无法找到显式活动类”

时间:2012-09-01 02:00:17

标签: android

我已经在这里工作了几个小时,无法弄明白。当我调试时,它给出了上述错误。我是新手,所以如果有一些明显的东西让我感到温和......

这是从第一个活动引入崩溃的代码,它仍然标记为'Main':

//-- 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;
    }

}

和第二个活动,目前名为'Menu':

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>

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

3 个答案:

答案 0 :(得分:12)

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

答案 1 :(得分: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>  

并查看是否有帮助

答案 2 :(得分:1)

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