public void save(View v) {
switch(v.getId()) {
case R.id.bSave:
filename = "data/monday.txt";
vsName.showPrevious();
vsTime.showPrevious();
vsQuantity.showPrevious();
vsImage.showPrevious();
save.setVisibility(View.GONE);
try{
monday = new File(filename);
if (!monday.exists()) {
if (!monday.createNewFile()) {
throw new IOException("Unable to create file");
}
}
fos = new FileOutputStream(monday);
oos = new ObjectOutputStream(fos);
oos.writeObject(etName.getText().toString());
oos.writeObject(etQuantity.getText().toString());
oos.writeObject(etTime.getText().toString());
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally{
try {
fos.close();
oos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
break;
}
}
That's the code for my save method. I want it to save the edittext so my textviews will stay even after i close the program. This is my first time using the fileoutputstreams so i don't know how to fix the problem. When i click the save button, it says unfortunately it has stopped.
05-22 15:32:40.095: E/AndroidRuntime(6984): FATAL EXCEPTION: main
05-22 15:32:40.095: E/AndroidRuntime(6984): java.lang.IllegalStateException: Could not execute method of the activity
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.view.View$1.onClick(View.java:3599)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.view.View.performClick(View.java:4204)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.view.View$PerformClick.run(View.java:17355)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.os.Handler.handleCallback(Handler.java:725)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.os.Handler.dispatchMessage(Handler.java:92)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.os.Looper.loop(Looper.java:137)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-22 15:32:40.095: E/AndroidRuntime(6984): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 15:32:40.095: E/AndroidRuntime(6984): at java.lang.reflect.Method.invoke(Method.java:511)
05-22 15:32:40.095: E/AndroidRuntime(6984): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-22 15:32:40.095: E/AndroidRuntime(6984): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-22 15:32:40.095: E/AndroidRuntime(6984): at dalvik.system.NativeStart.main(Native Method)
05-22 15:32:40.095: E/AndroidRuntime(6984): Caused by: java.lang.reflect.InvocationTargetException
05-22 15:32:40.095: E/AndroidRuntime(6984): at java.lang.reflect.Method.invokeNative(Native Method)
05-22 15:32:40.095: E/AndroidRuntime(6984): at java.lang.reflect.Method.invoke(Method.java:511)
05-22 15:32:40.095: E/AndroidRuntime(6984): at android.view.View$1.onClick(View.java:3594)
05-22 15:32:40.095: E/AndroidRuntime(6984): ... 11 more
05-22 15:32:40.095: E/AndroidRuntime(6984): Caused by: java.lang.NullPointerException
05-22 15:32:40.095: E/AndroidRuntime(6984): at tbjsoft.medicationreminder.Monday.save(Monday.java:170)
05-22 15:32:40.095: E/AndroidRuntime(6984): ... 14 more