嘗試運行應用程序時,我意外地收到以下NullPointer異常錯誤。NullPointerException - Fragment問題
09-22 18:30:49.053: E/AndroidRuntime(3731): FATAL EXCEPTION: main
09-22 18:30:49.053: E/AndroidRuntime(3731): Process: com.dooba.beta, PID: 3731
09-22 18:30:49.053: E/AndroidRuntime(3731): java.lang.NullPointerException
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.dooba.beta.Fragment2$5.done(Fragment2.java:410)
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.parse.FindCallback.internalDone(FindCallback.java:45)
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.parse.FindCallback.internalDone(FindCallback.java:31)
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.parse.Parse$6$1.run(Parse.java:917)
09-22 18:30:49.053: E/AndroidRuntime(3731): at android.os.Handler.handleCallback(Handler.java:733)
09-22 18:30:49.053: E/AndroidRuntime(3731): at android.os.Handler.dispatchMessage(Handler.java:95)
09-22 18:30:49.053: E/AndroidRuntime(3731): at android.os.Looper.loop(Looper.java:136)
09-22 18:30:49.053: E/AndroidRuntime(3731): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-22 18:30:49.053: E/AndroidRuntime(3731): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 18:30:49.053: E/AndroidRuntime(3731): at java.lang.reflect.Method.invoke(Method.java:515)
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-22 18:30:49.053: E/AndroidRuntime(3731): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-22 18:30:49.053: E/AndroidRuntime(3731): at dalvik.system.NativeStart.main(Native Method)
我行410是如下:
mUserActivityTitleNameRetrieved2 = (TextView) getActivity().findViewById(R.id.tactivityname2);
如果你需要任何澄清,讓我知道。 在此先感謝
可能意味着getActivity()的結果返回null – ControlAltDel 2014-09-22 18:47:19
看來getActivity()返回null。 – 2014-09-22 18:49:20
感謝您的回覆。會使用getView更好嗎? – John 2014-09-22 18:53:44