Answer the question
In order to leave comments, you need to log in
What is the cause of this error?
Hello.
I send a POST request to the server, the server returns a json of the form in the following format:
{"status":"OK","token":"5de99ea9a1bb550c02a8c2c74e79ac485707dce021cd2b021c8b4567"}
if (json != null) {
try {
String jsonstr = json.getString("status");
if (json.has("status")) {
String token = json.getString("token");
SharedPreferences.Editor editor = sharedPreferences.edit(); // 70 строчка на которую ссылается лог
editor.putString("token", token);
editor.apply();
Intent intent = new Intent(Login.this, Main.class);
startActivity(intent);
finish();
}
04-10 20:19:30.576 32229-32446/com.dpa7dujijiepgmail.application E/JSON: {"status":"OK","token":"117248e6234b67a6aaa96489ea5fba735707dce021cd2b021c8b4567"}n
04-10 20:19:30.576 32229-32229/com.dpa7dujijiepgmail.application W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0xa62c9288)
04-10 20:19:30.580 32229-32229/com.dpa7dujijiepgmail.application E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at com.dpa7dujijiepgmail.application.Login$1.onClick(Login.java:70)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
04-10 20:19:33.244 32229-32229/com.dpa7dujijiepgmail.application I/Process: Sending signal. PID: 32229 SIG: 9
Answer the question
In order to leave comments, you need to log in
Well, since there is only one call in this line - sharedPreferences.edit(); and we see NullPointerException, then the output is banal - sharedPreferences == null. Fix this and you'll be fine.
Yes, indeed, I don’t know how I forgot not to do getSharedPreferences. Thanks for answers.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question