EOFException error on using Storage with an externalizable object.

103 views
Skip to first unread message

steve

unread,
May 8, 2014, 12:19:43 AM5/8/14
to codenameone...@googlegroups.com
Hi,

I've been using externalizable objects and whatever is in Storage I read them and put them in a Vector object ie
 Vector<Proprietary Object>=(Vector<Proprietary Object>)Storage.getInstance().readObject("storeName");
This has been working without a hitch but when I try the method shown in Steve Hannah's blog ie;
ProprietaryObject po=(ProprietaryObject )Storage.getInstance().readObject("storeName");
Object po stores user details eg.UserId,role ,Name etc.
The code works for the first time but when i re-run the program (after successfully logging in and working with Object po, during the first time), it seems nothing was stored because I have to log in again, and I also get an EOF exception:

java.io.EOFException
 at java
.io.DataInputStream.readFully(DataInputStream.java:197)
 at java
.io.DataInputStream.readUTF(DataInputStream.java:609)
 at java
.io.DataInputStream.readUTF(DataInputStream.java:564)
 at com
.codename1.io.Util.readUTF(Util.java:969)
 at com
.sematime.bulksms.userinfo.UserInfo.internalize(UserInfo.java:70)
 at com
.codename1.io.Util.readObject(Util.java:624)
 at com
.codename1.io.Storage.readObject(Storage.java:236)
 at com
.sematime.bulksms.Main.start(Main.java:40)
 at sun
.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun
.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun
.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 at java
.lang.reflect.Method.invoke(Method.java:601)
 at com
.codename1.impl.javase.Executor$1.run(Executor.java:95)
 at com
.codename1.ui.Display.processSerialCalls(Display.java:1075)
 at com
.codename1.ui.Display.mainEDTLoop(Display.java:897)
 at com
.codename1.ui.RunnableWrapper.run(RunnableWrapper.java:120)
 at com
.codename1.impl.CodenameOneThread.run(CodenameOneThread.java:176)

What could be the issue? Any help will be greatly appreciated. Find attached the relevant source code. 

Regards,
Steve.
UserInfo.java
Main.java

Shai Almog

unread,
May 8, 2014, 2:05:55 AM5/8/14
to codenameone...@googlegroups.com
Hi,
It works for the first time because the object is in the cache. Please use embedding for sources rather than attaching:
    public void externalize(DataOutputStream out) throws IOException {
       
Util.writeUTF(name, out);
       
Util.writeObject(role, out);
       
Util.writeUTF(email, out);
       
Util.writeUTF(userId, out);
   
}

   
public void internalize(int version, DataInputStream in) throws IOException {
        name
=Util.readUTF(in);
        role
=Util.readUTF(in);
        email
=Util.readUTF(in);
        userId
=Util.readUTF(in);        
   
}


Look at role. You write an object but then read a UTF...

steve

unread,
May 8, 2014, 3:31:58 AM5/8/14
to codenameone...@googlegroups.com
hi,

Thanks...I honestly had not seen that...thanks again...

I'll be embedding them hopefully the post won't be long..

Regards,
Steve.
Reply all
Reply to author
Forward
0 new messages