android - Unable to access sharedpreference from one class to another -


hi developing android opengl live wallpaper. unable access shared preference wallpaperservice renderer class.i getting error like:

06-26 01:42:38.285: e/androidruntime(4778): fatal exception: main 06-26 01:42:38.285: e/androidruntime(4778): java.lang.classcastexception: java.lang.integer cannot cast java.lang.string 06-26 01:42:38.285: e/androidruntime(4778):     @ android.app.sharedpreferencesimpl.getstring(sharedpreferencesimpl.java:224) 06-26 01:42:38.285: e/androidruntime(4778):     @ com.srashtaa.planets3dgalaxylivewallpaper.nehelesson08renderer.loadpreferences(nehelesson08renderer.java:155) 06-26 01:42:38.285: e/androidruntime(4778):     @ com.srashtaa.planets3dgalaxylivewallpaper.nehelesson08renderer.setcontext(nehelesson08renderer.java:146) 06-26 01:42:38.285: e/androidruntime(4778):     @ com.srashtaa.planets3dgalaxylivewallpaper.nehelesson08wallpaperservice$myengine.<init>(nehelesson08wallpaperservice.java:42) 06-26 01:42:38.285: e/androidruntime(4778):     @ com.srashtaa.planets3dgalaxylivewallpaper.nehelesson08wallpaperservice.oncreateengine(nehelesson08wallpaperservice.java:26) 

this code:

         sharedpreferences = getsharedpreferences(preferences, mode_private);          string rotspeed = null;          string storedpreference = sharedpreferences.getstring("rotspeed", "key");          sharedpreferences.editor editor = sharedpreferences.edit();          editor.putstring("rotspeed", storedpreference); // value store          editor.commit();          string check=sharedpreferences.getstring("rotspeed", "");          system.out.println("stored procedure values::"+check); 

here trying preference value,

               prefs= preferencemanager.getdefaultsharedpreferences(value);                storedpreference= prefs.getstring("rotspeed","0"); 

can tell me why error?

06-26 01:42:38.285: e/androidruntime(4778): java.lang.classcastexception: java.lang.integer cannot cast java.lang.string 

this line states you're trying cast integer string. hence crash. make sure if you've saved value string in sharedprefs, you're retrieving string.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -