1

我想在android中使用菜单功能从一个类导航到另一个类..我该怎么做?请帮助...这是我的代码:

     public boolean onCreateOptionsMenu(Menu menu)
 {

    menu.add("View Map");
     MenuInflater inflater= getMenuInflater();
     inflater.inflate(R.menu.menu, menu);
     return true;

 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item)
 {
     switch(item.getItemId())
     {
     case R.id.viewMap: {
         Intent in=new Intent(Service.this,Map.class);
                             startActivity(in);}
                             break;
     }          
     return true;
 }

我收到这些错误:

04-12 21:27:01.436: E/AndroidRuntime(543): FATAL EXCEPTION: main
04-12 21:27:01.436: E/AndroidRuntime(543): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aid/com.aid.Map}: java.lang.NullPointerException
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.os.Looper.loop(Looper.java:130)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread.main(ActivityThread.java:3683)
04-12 21:27:01.436: E/AndroidRuntime(543):  at java.lang.reflect.Method.invokeNative(Native Method)
04-12 21:27:01.436: E/AndroidRuntime(543):  at java.lang.reflect.Method.invoke(Method.java:507)
04-12 21:27:01.436: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-12 21:27:01.436: E/AndroidRuntime(543):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-12 21:27:01.436: E/AndroidRuntime(543):  at dalvik.system.NativeStart.main(Native Method)
04-12 21:27:01.436: E/AndroidRuntime(543): Caused by: java.lang.NullPointerException
04-12 21:27:01.436: E/AndroidRuntime(543):  at com.aid.Map.onCreate(Map.java:59)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-12 21:27:01.436: E/AndroidRuntime(543):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
4

1 回答 1

0

您正确启动了活动,但地图活动中有错误。您在 Map.java 第 59 行中得到一个空指针异常,该异常会使您的应用程序崩溃。这些行指出了错误:

E/AndroidRuntime(543): Caused by: java.lang.NullPointerException 04-12 21:27:01.436:            
E/AndroidRuntime(543): at com.aid.Map.onCreate(Map.java:59) 04-12 21:27:01.436: 
于 2012-04-12T16:07:00.247 回答