UTFDataFormatException: encoded string too long: 127155 bytes

673 views
Skip to first unread message

Gareth Murfin

unread,
Jan 27, 2014, 6:00:54 AM1/27/14
to codenameone...@googlegroups.com
Im getting this error:
UTFDataFormatException: encoded string too long

When I erite a large chunk of json to internal storage. It was working fine but the json has been increased in size on the server side a lot. I seem to recall this from J2ME, just wondering what the solution is? If I recall I made it so that everything that was written was written in chunks of 127k each, this was a nightmare. In this situation it might be difficult too because of the way im writing records each with a name and an ID, I guess I could split them up maybe still.

Is there any simple/nicer way to get around this ?

Gareth Murfin

unread,
Jan 27, 2014, 6:15:08 AM1/27/14
to codenameone...@googlegroups.com
Strange this is this continues to happen even when I write only a tiny amount of data, I guess it has already crashed internally by then ? 

I tried writing "{SERVICE#0} = {SERVICE} 27/7/2014^www^ddw"

and got 

java.io.UTFDataFormatException: encoded string too long: 127155 bytes
at java.io.DataOutputStream.writeUTF(DataOutputStream.java:364)
at java.io.DataOutputStream.writeUTF(DataOutputStream.java:323)
at com.codename1.io.Util.writeObject(Util.java:258)
at com.codename1.io.Util.writeObject(Util.java:240)
at com.codename1.io.Storage.writeObject(Storage.java:205)
at com.codename1.io.Preferences.save(Preferences.java:51)
at com.codename1.io.Preferences.set(Preferences.java:66)
at com.codename1.io.Preferences.set(Preferences.java:76)
at userclasses.silverputtyone.InternalStorage.writeValue(InternalStorage.java:47)
at userclasses.NavigationLogic.addService(NavigationLogic.java:3747)

Shai Almog

unread,
Jan 27, 2014, 12:46:34 PM1/27/14
to codenameone...@googlegroups.com
With larger values you would also get a size benefit by converting the JSON string to bytes using getBytes() or equivalent and saving that.
Reply all
Reply to author
Forward
0 new messages