0
try {
        FileInputStream fis = new FileInputStream(f);
        Log.d("Objects remaining; ", fis.available()+"");
        ObjectInputStream ois = new ObjectInputStream(fis);
        Log.d("Objects remaining; ", fis.available() + "");
        Question question = (Question) ois.readObject();
        Log.d("FIS:",fis.toString());
        Log.d("OIS:",ois.toString());
    } catch (Exception e){
        e.printStackTrace();
    }

}

I can't figure how to handle the given exception in my code.

11-06 12:49:52.879  27005-27005/com.example.android.fileio D/Objects remaining;﹕ 4
11-06 12:49:52.880  27005-27005/com.example.android.fileio D/Objects remaining;﹕ 0
11-06 12:49:52.880  27005-27005/com.example.android.fileio W/System.err﹕ java.io.EOFException
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.io.DataInputStream.readByte(DataInputStream.java:77)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.io.ObjectInputStream.nextTC(ObjectInputStream.java:505)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:752)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1983)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1940)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at com.example.android.fileio.MainActivity.makeFile(MainActivity.java:71)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.support.v7.internal.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:273)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.view.View.performClick(View.java:4756)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.view.View$PerformClick.run(View.java:19748)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:739)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5254)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
11-06 12:49:52.881  27005-27005/com.example.android.fileio W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
Bhargav
  • 8,118
  • 6
  • 40
  • 63

1 Answers1

1

There are 4 bytes available on the stream. Probably your serialized Question object would be larger than four bytes. I think this produces the EOFException. You have handled the exception by printing a stack trace. Are you sure the file contains what you expect?

yasd
  • 916
  • 7
  • 21
  • Well. It's the opposite. There is obviously no `Question` in the stream. The 4 bytes are some header bytes written by `ObjectOutputStream` and read by `ObjectInputStream`. So in fact, the stream does not contain any serialized object. – Seelenvirtuose Nov 06 '15 at 07:49
  • @Seelenvirtuose Yep, updated my misleading wording. Thx. – yasd Nov 06 '15 at 07:55
  • Ah! You are right, I misunderstood. You already said, what I simply repeated. Sorry. – Seelenvirtuose Nov 06 '15 at 08:14