Intent intent = new Intent(getActivity()。getApplicationContext(),XYZ.class)空指针异常

时间:2016-06-04 06:14:45

标签: android android-intent

我面临的问题是,当我想转移到新活动时,我面临空指针异常,

Fatal Exception: java.lang.NullPointerException
   at my.packname.fragments.CustomClass.handleResponse(Unknown Source:209)
   at my.packname.controllers.CustomClassController$1.onResponse(Unknown Source:114)
   at my.packname.controllers.CustomClassController$1.onResponse(Unknown Source:70)
   at com.android.volley.toolbox.JsonRequest.deliverResponse(Unknown Source:72)
   at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(Unknown Source: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:5086)
   at java.lang.reflect.Method.invokeNative(Method.java)
   at java.lang.reflect.Method.invoke(Method.java:515)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
   at dalvik.system.NativeStart.main(NativeStart.java)

我的代码是,

Intent intent = new Intent(getActivity().getApplicationContext(), XYZ.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK |   intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

1 个答案:

答案 0 :(得分:-1)

试试这个

startActivity(new Intent(getActivity(), XYZ.class));