android - Shared prefrenences input error due to Gson -


i io exception every time try save object json shared preferences.

w/sharedpreferencesimpl: writetofile: got exception:     java.io.ioexception: java.nio.charset.coderresult[malformed-input error erroneous input length 1]     @ com.android.internal.util.fastxmlserializer.flush(fastxmlserializer.java:245)     @ com.android.internal.util.fastxmlserializer.enddocument(fastxmlserializer.java:198)     @ com.android.internal.util.xmlutils.writemapxml(xmlutils.java:193)     @ android.app.sharedpreferencesimpl.writetofile(sharedpreferencesimpl.java:600)     @ android.app.sharedpreferencesimpl.-wrap2(sharedpreferencesimpl.java)     @ android.app.sharedpreferencesimpl$2.run(sharedpreferencesimpl.java:515)     @ android.app.sharedpreferencesimpl.enqueuediskwrite(sharedpreferencesimpl.java:536)     @ android.app.sharedpreferencesimpl.-wrap0(sharedpreferencesimpl.java)     @ android.app.sharedpreferencesimpl$editorimpl.commit(sharedpreferencesimpl.java:458) 

from log seams give bad string don't know wrong.

my code causes is:

gson gson = new gson(); string json = gson.tojson(value);  sharedpreferences prefs = getsharedprefs(ctx); prefs.edit().putstring(key, json).commit(); 

is there way of fixing without writing wild objectoutputstream ?

update

my json trying write looks when print log:

 {"coordinates":{"latitude":54.55445,"longitude":25.54581,"mversioncode":1},"name":"cityname"} 

update 2

preferencemanager.getdefaultsharedpreferences(ctx); 

this line causing in given code line in getsharedprefs(context); method. when use context.getsharedpreferences(set, context.mode_private); somehow works fine.

tho notice no matter value put shared preferences exception (from default shared preferences).

in test app wrote, no errors occurs if try save big json 1000 different preferences.

app thorws exception way bigger , uses multidex.


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -