Intent i = new Intent(getActivity(), MytabActivity.class);
startActivity(i);
My DialogFragment
opens when a button is clicked from the calling activity. I does what it's asked for and was able to function all the part of the code except opening to another activity after a successful response from the server (I'm using volley). The values did change but it crashes in this part.
Any ideas?
Here a screenshot of the code.
logcat:
03-05 03:30:11.570 16952-16952/com.example.carlajoyce.ccare E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.carlajoyce.ccare, PID: 16952
java.lang.NullPointerException
at android.widget.Toast.<init>(Toast.java:93)
at android.widget.Toast.makeText(Toast.java:241)
at com.example.carlajoyce.ccare.UpdateDialogFragment$2$1.onResponse(UpdateDialogFragment.java:73)
at com.example.carlajoyce.ccare.UpdateDialogFragment$2$1.onResponse(UpdateDialogFragment.java:64)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:801)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:617)
at dalvik.system.NativeStart.main(Native Method)
The crash may be because you call the Intent from background thread. Make sure you are calling the Intent from Main Thread inside your Activity
Try to cast your intent inside the following:
context.runOnUiThread(new Runnable() {
public void run() {
//INTENT HERE
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.