protected void onDestroy() {
try{
out.close();
fos.close();
}catch(IOException e){
e.printStackTrace();
}
super.onDestroy();
}
Process: com.example.hello.myapplication, PID: 23296
java.lang.RuntimeException: Unable to destroy activity {com.example.seokh.myapplication/com.example.seokh.myapplication.MainActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.FileInputStream.close()' on a null object reference
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4561)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4584)
at android.app.ActivityThread.-wrap7(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1689)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6646)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void java.io.FileInputStream.close()' on a null object reference
at com.example.seokh.myapplication.MainActivity.onDestroy(MainActivity.java:74)
at android.app.Activity.performDestroy(Activity.java:7165)
at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1161)
at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:4548)
at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:4584)
at android.app.ActivityThread.-wrap7(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1689)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6646)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
onDestroy말고 다른 메서드에선 close메서드를 부르는 곳이 없고 저장도 멀쩡히 됩니다. 그런데 닫고 나면 nullpointerException이 발생하네요.
out.close;와 fos.close;를 주석처리하면 에러는 없는데 저장은 안되구요. onDestroy에서 닫으면 안되는 건가요???