我不确定为什么我一直收到空指针错误:
这是错误:
11-06 13:50:03.539 27297-27297/com.example.lior.winklio E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example, PID: 27297
java.lang.NullPointerException
at android.content.ComponentName.<init>(ComponentName.java:77)
at android.content.Intent.<init>(Intent.java:3813)
at com.example.StarterFragment.sendToHomePage(StarterFragment.java:227)
at com.example.StarterFragment.access$1700(StarterFragment.java:37)
at com.example.StarterFragment$2.success(StarterFragment.java:184)
at com.example.StarterFragment$2.success(StarterFragment.java:176)
at retrofit.CallbackRunnable$1.run(CallbackRunnable.java:45)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
这是代码:(错误指向Intent homeInter ...)
private void sendToHomePage() {
Log.i(TAG, " SENDING TO HOME PAGE...");
Intent homeIntent = new Intent(getActivity(), MainActivity.class);
// Closing all the Activities
homeIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
// Add new Flag to start new Activity
homeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Staring add item
startActivity(homeIntent);
getActivity().finish();
}
答案 0 :(得分:0)
使用:
Intent homeIntent = new Intent(getActivity().getApplicationContext, MainActivity.class);