One person reports a crash with a null pointer when accessing shared
preferences. Strangely, the same code works if used in a different
package (I distribute the same code com.mobitobi.android.gentlealarm
also as a beta com.mobitobi.android.gentlealarmbeta). I can not
reproduce the error myself but I got a log from the user who reported
the crash:

This code crashes and the log shows a NULL pointer. How can there be a
null point on this line?:
(932)     switch (Preferences.getPrefOrientation(this, Screen.MAIN)) {
...
}

Screen is an enum:
    public enum Screen { MAIN, NIGHT, ALARM };

And the getPrefOrientation is STATIC:
    public static int getPrefOrientation (Context context, Screen
screen)
    {
        if (getPrefAdvanced(context)) {
            String pref = ORIENT_ + screen.toString().toLowerCase();
            return
Integer.parseInt(PreferenceManager.getDefaultSharedPreferences(context).getString(pref,
Integer.toString(0)));
        }
        else
            return 0;
    }


And the log:

01-30 07:31:51.974 I/ActivityManager(   74): Start proc
com.mobitobi.android.gentlealarm for activity
com.mobitobi.android.gentlealarm/.Activity_Main: pid=2975 uid=10035
gids={1015, 3003, 1007}
01-30 07:31:52.164 I/dalvikvm( 2975): Debugger thread not active,
ignoring DDM send (t=0x41504e4d l=38)
01-30 07:31:52.254 I/dalvikvm( 2975): Debugger thread not active,
ignoring DDM send (t=0x41504e4d l=68)
01-30 07:31:52.524 D/ACRA    ( 2975): Retrieve application default
SharedPreferences.
01-30 07:31:52.534 D/ACRA    ( 2975): Set
OnSharedPreferenceChangeListener.
01-30 07:31:52.554 D/ACRA    ( 2975): ACRA is enabled for
com.mobitobi.android.gentlealarm, intializing...
01-30 07:31:52.604 D/ACRA    ( 2975): Looking for error files in /data/
data/com.mobitobi.android.gentlealarm/files
01-30 07:31:52.624 D/ACRA    ( 2975): Looking for error files in /data/
data/com.mobitobi.android.gentlealarm/files
01-30 07:31:54.614 I/GentleAlarm( 2975): Activity_Main:
resumeCurrentActivity MAIN
01-30 07:31:54.844 D/AndroidRuntime( 2975): Shutting down VM
01-30 07:31:54.844 W/dalvikvm( 2975): threadid=3: thread exiting with
uncaught exception (group=0x4001da28)
01-30 07:31:55.004 D/ACRA    ( 2975): Writing crash report file.
01-30 07:31:55.414 E/ACRA    ( 2975): Gentle Alarm fatal error :
Unable to start activity
ComponentInfo{com.mobitobi.android.gentlealarm/
com.mobitobi.android.gentlealarm.Activity_Main}:
java.lang.NullPointerException
01-30 07:31:55.414 E/ACRA    ( 2975): java.lang.RuntimeException:
Unable to start activity
ComponentInfo{com.mobitobi.android.gentlealarm/
com.mobitobi.android.gentlealarm.Activity_Main}:
java.lang.NullPointerException
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2401)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2417)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.ActivityThread.access$2100(ActivityThread.java:116)
01-30 07:31:55.414 E/ACRA    ( 2975): at android.app.ActivityThread
$H.handleMessage(ActivityThread.java:1794)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.os.Handler.dispatchMessage(Handler.java:99)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.os.Looper.loop(Looper.java:123)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.ActivityThread.main(ActivityThread.java:4203)
01-30 07:31:55.414 E/ACRA    ( 2975): at
java.lang.reflect.Method.invokeNative(Native Method)
01-30 07:31:55.414 E/ACRA    ( 2975): at
java.lang.reflect.Method.invoke(Method.java:521)
01-30 07:31:55.414 E/ACRA    ( 2975): at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
01-30 07:31:55.414 E/ACRA    ( 2975): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
01-30 07:31:55.414 E/ACRA    ( 2975): at
dalvik.system.NativeStart.main(Native Method)
01-30 07:31:55.414 E/ACRA    ( 2975): Caused by:
java.lang.NullPointerException
01-30 07:31:55.414 E/ACRA    ( 2975): at
com.mobitobi.android.gentlealarm.Activity_Main.start(Activity_Main.java:
932)
01-30 07:31:55.414 E/ACRA    ( 2975): at
com.mobitobi.android.gentlealarm.Activity_Main.onCreate(Activity_Main.java:
715)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1123)
01-30 07:31:55.414 E/ACRA    ( 2975): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2364)
01-30 07:31:55.414 E/ACRA    ( 2975): ... 11 more
01-30 07:31:55.454 I/Process ( 2975): Sending signal. PID: 2975 SIG: 9
01-30 07:31:55.474 I/ActivityManager(   74): Process
com.mobitobi.android.gentlealarm (pid 2975) has died.
01-30 07:31:55.504 W/UsageStats(   74): Unexpected resume of
com.android.launcher while already resumed in
com.mobitobi.android.gentlealarm

The null pointer is at line 932 so it must be this line:
switch (Preferences.getPrefOrientation(this, Screen.MAIN))

and Preferences.getPrefOrientation is a static function.

I assumed a problem with the installation and asked the user to
uninstall and reinstall a new compilation I sent him; no change.

Any help would be greatly appreciated.

Martin
mobitobi

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to