当我执行我得到 NPE 的行时,FileInputStream ifs=openFileInput(fileName);
我有一个 NPE。执行时得到相同的 NPE
FileInputStream ifs=getApplicationContext().openFileInput(fileName);
完整的堆栈跟踪在这里。
07-25 22:00:35.852 25063-25063/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at android.content.ContextWrapper.getApplicationContext(ContextWrapper.java:109)
at com.ollien.flashcarder.MainActivity.setPagerFile(MainActivity.java:353)
at com.ollien.flashcarder.SetsFragment$1.onItemClick(SetsFragment.java:47)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1215)
at android.widget.ListView.performItemClick(ListView.java:4506)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2959)
at android.widget.AbsListView$1.run(AbsListView.java:3645)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:158)
at android.app.ActivityThread.main(ActivityThread.java:5751)
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:1083)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:850)
at dalvik.system.NativeStart.main(Native Method)
有人可以帮忙吗?我不太清楚为什么会这样。fileName 不为空,等于"hi there.txt"
Thanks!