Search code examples
androidnullpointerexceptionrevision

Android SDK Update (revision 18) causes NullPointer Exception


Slowly but surely I hat to update the android SDK…

Today I update the SDK to revision 18 and my project (before the update perfectly working) throws a NullPointer Exception even I just start it up from eclipse. I’m using eclipse with the android ADT and also update this part after update the SDK. I also tried “Fix Project Properties” with no result.

In the meanwhile my project is quit big so for the start I just post the LogCat messages, if someone need more just say it, I will post it. But I’m really disappointed that every time I update the SDK my project throws some new, mysterious errors (run into the external lib problem with revision 17…).

Hope someone can help me out! I don’t think it’s a problem with the code anyway. Its something they changed somewhere I don’t know :/

[Update]

I get some extra time to debug the code. The problem occurs in the construtor. It look like this (suprise, suprise):

@Override
public void onCreate(Bundle _savedInstanceState) 
{   /// Einstiegspunkt der Android App
    super.onCreate(_savedInstanceState);       
    setContentView(R.layout.login);
    LoadSharedPreferences();
}

The exception throws after the activity tries to go to the LoadSharedPrefrerences method...

[Update: Code around line 49]

...
SharedPreferences data = getSharedPreferences(_saveUserDataRef, MODE_PRIVATE);
String tmpUsername = data.getString("username", null);
String tmpPassword = data.getString("password", null);
username.setText(tmpUsername);
password.setText(tmpPassword);
...

This snippet save the username and password if you want the app to remeber these data for you. So you dont need to write it everytime you log on.

LogCat:

04-12 12:09:47.615: D/dalvikvm(1094): GC_EXTERNAL_ALLOC freed 47K, 48% free 2835K/5379K, external 0K/0K, paused 78ms
04-12 12:09:47.686: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.686: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.696: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.716: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.716: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.716: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$START@401462d0,-1,0,-1,0)
04-12 12:09:47.716: I/[POST_RESELECT](1094): [spanChange] (o, oldStart, newStart, oldEnd, newEnd)=(android.text.Selection$END@4011b730,-1,0,-1,0)
04-12 12:09:47.716: D/AndroidRuntime(1094): Shutting down VM
04-12 12:09:47.716: W/dalvikvm(1094): threadid=1: thread exiting with uncaught exception (group=0x400205a0)
04-12 12:09:47.726: E/AndroidRuntime(1094): FATAL EXCEPTION: main
04-12 12:09:47.726: E/AndroidRuntime(1094): java.lang.RuntimeException: Unable to start activity ComponentInfo{de.tzm.seanwesenheitsliste/de.tzm.seanwesenheitsliste.SEAnwesenheitslisteMainActivity}: java.lang.NullPointerException
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread.access$1500(ActivityThread.java:132)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.os.Looper.loop(Looper.java:150)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread.main(ActivityThread.java:4277)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at java.lang.reflect.Method.invokeNative(Native Method)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at java.lang.reflect.Method.invoke(Method.java:507)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at dalvik.system.NativeStart.main(Native Method)
04-12 12:09:47.726: E/AndroidRuntime(1094): Caused by: java.lang.NullPointerException
04-12 12:09:47.726: E/AndroidRuntime(1094):     at de.tzm.seanwesenheitsliste.SEAnwesenheitslisteMainActivity.LoadSharedPreferences(SEAnwesenheitslisteMainActivity.java:49)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at de.tzm.seanwesenheitsliste.SEAnwesenheitslisteMainActivity.onCreate(SEAnwesenheitslisteMainActivity.java:32)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
04-12 12:09:47.726: E/AndroidRuntime(1094):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
04-12 12:09:47.726: E/AndroidRuntime(1094):     ... 11 more

Solution

  • I can't tell from your post which line is line 49, but my guess is:

    either: data is null after getSharedPreferences(_saveUserDataRef, MODE_PRIVATE);

    or: one of tmpUsername or tmpPassword is null after trying to get them from data.

    Can you try find out if that's the case? If so, you'll know where to look next to solve the problem.