codenameone - EOFException when reading file from storage (cn1) -
i have made externalizable object - user. works fine when writing , reading storage except if exit app , reopen it. error occurs:
java.io.eofexception @ java.io.datainputstream.readfully(datainputstream.java:197) @ java.io.datainputstream.readutf(datainputstream.java:609) @ java.io.datainputstream.readutf(datainputstream.java:564) @ com.codename1.io.util.readutf(util.java:962)
i have registered class follows in statemachine:
@override protected void initvars(resources res) { util.register("user", user.class); }
this class:
package userclasses; import com.codename1.io.externalizable; import com.codename1.io.util; import java.io.datainputstream; import java.io.dataoutputstream; import java.io.ioexception; import java.util.date; /** * * */ public class user implements externalizable { private static final int version = 1; public int userid; public string username; public string password; public string firstname; public string surname; public string email; public date registerdate; public boolean paiduser; public double runstep; public double walkstep; public user(){ } @override public int getversion() { return version; } @override public void externalize(dataoutputstream out) throws ioexception { out.write(userid); util.writeutf(username, out); util.writeutf(password, out); util.writeutf(firstname, out); util.writeutf(surname, out); util.writeutf(email, out); out.writelong(registerdate.gettime()); out.writeboolean(paiduser); out.writedouble(runstep); out.writedouble(walkstep); } @override public void internalize(int version, datainputstream in) throws ioexception { userid = in.readint(); username = util.readutf(in); password = util.readutf(in); firstname = util.readutf(in); surname = util.readutf(in); email = util.readutf(in); registerdate = new date(in.readlong()); paiduser = in.readboolean(); runstep = in.readdouble(); walkstep = in.readdouble(); } @override public string getobjectid() { return "user"; } }
replace:
out.write(userid);
with:
out.writeint(userid);
the default write method equivalent of writebyte
.
Comments
Post a Comment