0

所以我试图让菜单充气机使用以下代码从我想要菜单的活动中工作。

当我单击该项目以打开我的应用程序关闭时,我只收到一条消息说不幸的是这个应用程序已停止运行。

谁能帮忙。

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
// TODO Auto-generated method stub
 super.onCreateOptionsMenu(menu);
 MenuInflater blowUp = getMenuInflater();
 blowUp.inflate(R.menu.cool_menu, menu);

 return true;
}

@Override

public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch(item.getItemId()){
case R.id.aboutUs:
    Intent i = new Intent(Menu.this, AboutUs.class);
    startActivity(i);
    break;
case R.id.prefs:

    break;
}
return false;
}

这是菜单项单击的类:

public class AboutUs extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.about);
}

日志猫:

03-05 14:12:25.265: D/AbsListView(21911): Get MotionRecognitionManager
03-05 14:12:25.545: E/SpannableStringBuilder(21911): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-05 14:12:25.545: E/SpannableStringBuilder(21911): SPAN_EXCLUSIVE_EXCLUSIVE spans cannot have a zero length
03-05 14:12:58.990: D/AbsListView(21911): Get MotionRecognitionManager
03-05 14:13:03.065: D/AndroidRuntime(21911): Shutting down VM
03-05 14:13:03.065: W/dalvikvm(21911): threadid=1: thread exiting with uncaught exception (group=0x40ee92a0)
03-05 14:13:03.080: E/AndroidRuntime(21911): FATAL EXCEPTION: main
03-05 14:13:03.080: E/AndroidRuntime(21911): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.learn.tam/com.example.learn.tam.AboutUs}; have you declared this activity in your AndroidManifest.xml?
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Activity.startActivityForResult(Activity.java:3446)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Activity.startActivityForResult(Activity.java:3407)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Activity.startActivity(Activity.java:3617)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Activity.startActivity(Activity.java:3585)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.example.learn.tam.Menu.onOptionsItemSelected(Menu.java:57)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.Activity.onMenuItemSelected(Activity.java:2629)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:1047)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:180)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.widget.AdapterView.performItemClick(AdapterView.java:301)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.widget.AbsListView.performItemClick(AbsListView.java:1276)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3067)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.widget.AbsListView$1.run(AbsListView.java:3963)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.os.Handler.handleCallback(Handler.java:615)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.os.Handler.dispatchMessage(Handler.java:92)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.os.Looper.loop(Looper.java:137)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at android.app.ActivityThread.main(ActivityThread.java:4898)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at java.lang.reflect.Method.invokeNative(Native Method)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at java.lang.reflect.Method.invoke(Method.java:511)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
03-05 14:13:03.080: E/AndroidRuntime(21911):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
03-05 14:13:03.080: E/AndroidRuntime(21911):at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

2

android.content.ActivityNotFoundException:找不到明确的活动类 {com.example.learn.tam/com.example.learn.tam.AboutUs};您是否在 AndroidManifest.xml 中声明了此活动?

在 中声明您的AboutUs活动AndroidManifest.xml。如果已声明,请确保声明中的包名称正确。

于 2013-03-05T14:18:45.593 回答