java - NullPointerException at the call of getDefaultSharedPreference -
this i've declared in contactactivity class
final sharedpreferences exceptionprefs = preferencemanager.getdefaultsharedpreferences(this); exceptionprefs.edit().putstring("exceptions", textutils.join(",", exceptions)).apply();
in different class (which not activity. extends broadcastreceiver
), on trying stored values sharedpreference
i'm using within onreceive()
-
sharedpreferences exceptionpositionprefs = preferencemanager.getdefaultsharedpreferences(new contactactivity().getcontext());
that line throws nullpointerexception.
also, must add together onreceive contains of sharedpreferences object, receives values mainactivity
.
here's 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 start receiver com.scimet.admin.driveon.rejectcall: java.lang.nullpointerexception 10-19 15:49:03.628: e/androidruntime(24226): @ android.app.activitythread.handlereceiver(activitythread.java:2146) 10-19 15:49:03.628: e/androidruntime(24226): @ android.app.activitythread.access$1500(activitythread.java:127) 10-19 15:49:03.628: e/androidruntime(24226): @ android.app.activitythread$h.handlemessage(activitythread.java:1208) 10-19 15:49:03.628: e/androidruntime(24226): @ android.os.handler.dispatchmessage(handler.java:99) 10-19 15:49:03.628: e/androidruntime(24226): @ android.os.looper.loop(looper.java:137) 10-19 15:49:03.628: e/androidruntime(24226): @ android.app.activitythread.main(activitythread.java:4441) 10-19 15:49:03.628: e/androidruntime(24226): @ java.lang.reflect.method.invokenative(native method) 10-19 15:49:03.628: e/androidruntime(24226): @ java.lang.reflect.method.invoke(method.java:511) 10-19 15:49:03.628: e/androidruntime(24226): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 10-19 15:49:03.628: e/androidruntime(24226): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 10-19 15:49:03.628: e/androidruntime(24226): @ 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): @ android.preference.preferencemanager.getdefaultsharedpreferencesname(preferencemanager.java:371) 10-19 15:49:03.628: e/androidruntime(24226): @ android.preference.preferencemanager.getdefaultsharedpreferences(preferencemanager.java:366) 10-19 15:49:03.628: e/androidruntime(24226): @ com.scimet.admin.driveon.rejectcall.onreceive(rejectcall.java:36) 10-19 15:49:03.628: e/androidruntime(24226): @ android.app.activitythread.handlereceiver(activitythread.java:2139) 10-19 15:49:03.628: e/androidruntime(24226): ... 10 more
the preferences utilize shared between activities.
preferencemanager.getdefaultsharedpreferences(ctx);
the above homecoming same preferences if ctx
mainactivity or contactactivity.
so can phone call broadcastreceiver ever context have available.
that beingness said if want activity-dependent preferences should calling context.getpreferences()
.
java android nullpointerexception
No comments:
Post a Comment