当我点击Android设备上的菜单按钮时,我想要一个菜单,我已经创建了一个方法和其他内容。这是在另一个项目上我接受了代码并将其改编成我的新项目!早些时候它运作良好bt,现在活动力量关闭!我找不到错误!请帮我!
方法---->
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.about:
Intent contextmenu = new Intent("com.sliit.droidman.main.About");
startActivity(contextmenu);
break;
case R.id.exit:
finish();
break;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
MenuInflater droidmenu = getMenuInflater();
droidmenu.inflate(R.menu.contextmenu, menu);
return true;
}
logcat日志,发生错误!
07-05 17:11:43.419: W/dalvikvm(4546): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
07-05 17:11:43.448: E/AndroidRuntime(4546): FATAL EXCEPTION: main
07-05 17:11:43.448: E/AndroidRuntime(4546): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=com.sliit.droidman.main.About }
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1416)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Activity.startActivityForResult(Activity.java:3351)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Activity.startActivityForResult(Activity.java:3312)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Activity.startActivity(Activity.java:3522)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.Activity.startActivity(Activity.java:3490)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.sliit.droidman.main.MainActivity.onMenuItemSelected(MainActivity.java:130)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:958)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:735)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:149)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:874)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.view.menu.ListMenuPresenter.onItemClick(ListMenuPresenter.java:166)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.widget.AdapterView.performItemClick(AdapterView.java:298)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.widget.AbsListView.performItemClick(AbsListView.java:1086)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2855)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.widget.AbsListView$1.run(AbsListView.java:3529)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.os.Handler.handleCallback(Handler.java:615)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.os.Handler.dispatchMessage(Handler.java:92)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.os.Looper.loop(Looper.java:137)
07-05 17:11:43.448: E/AndroidRuntime(4546): at android.app.ActivityThread.main(ActivityThread.java:4745)
07-05 17:11:43.448: E/AndroidRuntime(4546): at java.lang.reflect.Method.invokeNative(Native Method)
07-05 17:11:43.448: E/AndroidRuntime(4546): at java.lang.reflect.Method.invoke(Method.java:511)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-05 17:11:43.448: E/AndroidRuntime(4546): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-05 17:11:43.448: E/AndroidRuntime(4546): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
要启动“关于”活动,只需使用
即可 startActivity(new Intent(this, About.class));
logcat错误意味着您的活动com.sliit.droidman.main.About
不存在,位于另一个项目中,或者未在清单中定义。
答案 1 :(得分:0)
您需要在清单文件中定义活动,查看清单并查看之前定义的活动并创建一个新活动并在需要的地方进行更改。
答案 2 :(得分:0)
尝试:
Intent intent = new Intent("com.sliit.droidman.main.About");
final ComponentName cn = new
ComponentName("com.sliit.droidman.main","com.sliit.droidman.main.About");
intent.setComponent(cn);
startActivity(intent);
<小时/> 并确保添加了
android.intent.action.DEFAULT
intent-filter with About as:
<activity android:name=".About"
android:label="@string/app_name">
</intent-filter>
<intent-filter>
<action android:name="com.sliit.droidman.main.About" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>