Reputation: 63
I'm getting overly frustrated with this issue. First of all, this did work fine with no issues, I have no idea why I'm now getting this error.
The application runs fine on my phone (v2.3.4) but not on one emulator (1.6 > 2.3)
The error I'm getting is 'NullPointerException' immediately after I load the application. Heres the DDMS
08-24 21:10:11.706: WARN/dalvikvm(423): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): FATAL EXCEPTION: main
08-24 21:10:11.726: ERROR/AndroidRuntime(423): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.app/com.myapp.app.SplashActivity}: java.lang.NullPointerException
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1622)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.os.Looper.loop(Looper.java:123)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.main(ActivityThread.java:3647)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at java.lang.reflect.Method.invokeNative(Native Method)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at java.lang.reflect.Method.invoke(Method.java:507)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at dalvik.system.NativeStart.main(Native Method)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): Caused by: java.lang.NullPointerException
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.myapp.app.SplashActivity.onCreate(SplashActivity.java:43)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
08-24 21:10:11.726: ERROR/AndroidRuntime(423): ... 11 more
OK, so I look up what caused the problem (08-24 21:10:11.726: ERROR/AndroidRuntime(423): at com.myapp.app.SplashActivity.onCreate(SplashActivity.java:43))
Here is my onCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.welcome);
Button playBtn = (Button) findViewById(R.id.playBtn);
playBtn.setOnClickListener(this);
Button settingsBtn = (Button) findViewById(R.id.settingsBtn);
settingsBtn.setOnClickListener(this);
Button rulesBtn = (Button) findViewById(R.id.rulesBtn);
rulesBtn.setOnClickListener(this);
Button exitBtn = (Button) findViewById(R.id.exitBtn);
exitBtn.setOnClickListener(this);
}
Line 43 is the last one: exitBtn.setOnClickListener(this);
This is handled later on in the app using a switch statement for each button, the only code for the exit button is 'finish();' but it crashes 'onCreate' not onClick.
This is making no sense to me, this used to work fine and I haven't changed the code relating to this since it previously worked. Also, the exit button is set up exactly the same as all the other buttons (in src and layout files), so why would it crash when it gets to the exit button? As I said, this works OK on my cyn7 device but not on any of the emulators (it did)
This app has taken a massive amount of work to get it to this point, I was just doing final tests when this began.. so infuriating!
Can anyone please offer any suggestions to fix or even as to why this may happen?
EDIT: OK, this is really strange. I commented out the Exit button. Now my 'Play' button does nothing (even in DDMS it shows up nothing) the settings up OK and the Rules crashes, with the same error for the Rules activity on a setOnClickListener(this). Which makes no sense as the settings activity also has a 'setOnClickListener'. What is going on?!
Upvotes: 1
Views: 3287
Reputation: 25074
Sounds like a corrupt worksapce. Android in Eclipse sometimes gets the autogenerated resource files out of sysnc with the actual layout. As Xion mentioned, a clean and rebuild will fix this via Project -> Clean... -> Clean all projects. Before doing this, ensure that Project -> Build Automatically is ticked.
Upvotes: 2