开发者

Switching from activity to MapActivity

        Button showmapButton = (Button)findViewById(R.id.showmap);
    showmapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
    Intent intent = new Intent(HomePage.this,
      ShowMap开发者_如何学C.class);
    intent.putExtra("username", value);
    startActivity(intent);
   }
        });

In my main menu i have a button 'ShowMap' Everytime i click on showmap my map will hit a null pointer exception causing the program to crash. 'ShowMap' works fi ne if i launch straight to that page without having a need to click button to call that activity.

I tried changing all my files to "extends MapActivity" instead of regular activitiy but the program will still crash whenever i click on show map


D/AndroidRuntime(  347): Shutting down VM
W/dalvikvm(  347): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
E/AndroidRuntime(  347): FATAL EXCEPTION: main
E/AndroidRuntime(  347): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mp/com.mp.ShowMap}: java.lang.NullPointerException
E/AndroidRuntime(  347):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
E/AndroidRuntime(  347):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
E/AndroidRuntime(  347):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
E/AndroidRuntime(  347):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
E/AndroidRuntime(  347):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(  347):    at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime(  347):    at android.app.ActivityThread.main(ActivityThread.java:4627)
E/AndroidRuntime(  347):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(  347):    at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime(  347):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
E/AndroidRuntime(  347):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
E/AndroidRuntime(  347):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(  347): Caused by: java.lang.NullPointerException
E/AndroidRuntime(  347):    at com.mp.ShowMap.onCreate(ShowMap.java:46)
E/AndroidRuntime(  347):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime(  347):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
E/AndroidRuntime(  347):    ... 11 more


Alright guys i found my NPE!

(Before)

public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

(After)

public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.map);

Some careless mistake as we are trying to integrate out assignment!

Thank you all :D


Intent intent = new Intent();
intent.setClass(AndroidGPSTrackingActivity.this, mapslayout.class);
startActivity(intent);



 <uses-library
            android:name="com.google.android.maps"
            android:required="true" />**
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜