应用程序崩溃菜单膨胀。怎么纠正?

时间:2013-03-05 14:05:49

标签: java android

因此,我正在尝试使用以下代码从我想要菜单的活动中获取菜单inflater。

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

任何人都可以提供帮助。

@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);
}

logcat的:

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)

1 个答案:

答案 0 :(得分:2)

  

android.content.ActivityNotFoundException:无法找到显式   activity class {com.example.learn.tam / com.example.learn.tam.AboutUs};   你有没有在AndroidManifest.xml中声明这个活动?

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