views:

123

answers:

2
        Button showmapButton = (Button)findViewById(R.id.showmap);
    showmapButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
    Intent intent = new Intent(HomePage.this,
      ShowMap.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

A: 
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
Houston we have a problem
problem still exist after commenting intent//intent.putExtra("username", value);
Houston we have a problem
Your NPE is right here at `com.mp.ShowMap.onCreate(ShowMap.java:46)`. Show us that line of code
Falmarri
A: 

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

Houston we have a problem