そのため、メニューが必要なアクティビティから次のコードを使用して、メニュー インフレータを動作させようとしています。
アイテムをクリックしてアプリを開くと、残念ながらこのアプリは実行を停止しましたというメッセージが表示されます。
誰でも助けることができます。
@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)