該呼叫就是我宣佈我ContactActivity類NullPointerException異常在getDefaultSharedPreference
final SharedPreferences exceptionPrefs = PreferenceManager.getDefaultSharedPreferences(this);
exceptionPrefs.edit().putString("Exceptions", TextUtils.join(",", exceptions)).apply();
在不同的類(這是不是一種活動。它擴展BroadcastReceiver
),就試圖讓存儲的值從SharedPreference
我使用這個內onReceive()
-
SharedPreferences exceptionPositionPrefs = PreferenceManager.getDefaultSharedPreferences(new ContactActivity().getContext());
這很行拋出一個NullPointerException。
而且,我必須補充一點的onReceive包含另一個SharedPreferences對象,它從我的MainActivity
接收值。
這裏的logcat的。
10-19 15:49:03.628: E/AndroidRuntime(24226): FATAL EXCEPTION: main
10-19 15:49:03.628: E/AndroidRuntime(24226): java.lang.RuntimeException: Unable to start receiver com.scimet.admin.driveon.RejectCall: java.lang.NullPointerException
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2146)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.app.ActivityThread.access$1500(ActivityThread.java:127)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.os.Handler.dispatchMessage(Handler.java:99)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.os.Looper.loop(Looper.java:137)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.app.ActivityThread.main(ActivityThread.java:4441)
10-19 15:49:03.628: E/AndroidRuntime(24226): at java.lang.reflect.Method.invokeNative(Native Method)
10-19 15:49:03.628: E/AndroidRuntime(24226): at java.lang.reflect.Method.invoke(Method.java:511)
10-19 15:49:03.628: E/AndroidRuntime(24226): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-19 15:49:03.628: E/AndroidRuntime(24226): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-19 15:49:03.628: E/AndroidRuntime(24226): at dalvik.system.NativeStart.main(Native Method)
10-19 15:49:03.628: E/AndroidRuntime(24226): Caused by: java.lang.NullPointerException
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.preference.PreferenceManager.getDefaultSharedPreferencesName(PreferenceManager.java:371)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.preference.PreferenceManager.getDefaultSharedPreferences(PreferenceManager.java:366)
10-19 15:49:03.628: E/AndroidRuntime(24226): at com.scimet.admin.driveon.RejectCall.onReceive(RejectCall.java:36)
10-19 15:49:03.628: E/AndroidRuntime(24226): at android.app.ActivityThread.handleReceiver(ActivityThread.java:2139)
10-19 15:49:03.628: E/AndroidRuntime(24226): ... 10 more
'新的ContactActivity()'...你不*在Android中創建*活動。 – 2014-10-19 11:07:04
@ S.D。在ContactActivity類的上下文中如何傳遞? – Slay 2014-10-19 11:13:18