java - PreferenceManager Trouble -
i have got self problem. have preferencemanager keeps track of preferences have default values , can set user @ run time. other day testing , input value apparently not handled way have set up. want load default values set in xml file application run again. right now, gets part loading value below
dr.sethrvmax(integer.parseint(prefs.getstring("hrvmaxkey", "100")));
and spits out error
02-23 20:35:31.454: error/androidruntime(276): fatal exception: main 02-23 20:35:31.454: error/androidruntime(276): java.lang.runtimeexception: unable start activity componentinfo{cpe495.smartapp/cpe495.smartapp.smartapp}: java.lang.numberformatexception: unable parse '7p-' integer 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread.performlaunchactivity(activitythread.java:2663) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2679) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread.access$2300(activitythread.java:125) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread$h.handlemessage(activitythread.java:2033) 02-23 20:35:31.454: error/androidruntime(276): @ android.os.handler.dispatchmessage(handler.java:99) 02-23 20:35:31.454: error/androidruntime(276): @ android.os.looper.loop(looper.java:123) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread.main(activitythread.java:4627) 02-23 20:35:31.454: error/androidruntime(276): @ java.lang.reflect.method.invokenative(native method) 02-23 20:35:31.454: error/androidruntime(276): @ java.lang.reflect.method.invoke(method.java:521) 02-23 20:35:31.454: error/androidruntime(276): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:868) 02-23 20:35:31.454: error/androidruntime(276): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:626) 02-23 20:35:31.454: error/androidruntime(276): @ dalvik.system.nativestart.main(native method) 02-23 20:35:31.454: error/androidruntime(276): caused by: java.lang.numberformatexception: unable parse '7p-' integer 02-23 20:35:31.454: error/androidruntime(276): @ java.lang.integer.parse(integer.java:433) 02-23 20:35:31.454: error/androidruntime(276): @ java.lang.integer.parseint(integer.java:422) 02-23 20:35:31.454: error/androidruntime(276): @ java.lang.integer.parseint(integer.java:382) 02-23 20:35:31.454: error/androidruntime(276): @ cpe495.smartapp.smartapp.oncreate(smartapp.java:90) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1047) 02-23 20:35:31.454: error/androidruntime(276): @ android.app.activitythread.performlaunchactivity(activitythread.java:2627) 02-23 20:35:31.454: error/androidruntime(276): ... 11 more
i load complete defaults xml instead of trying load last saved preference. have tried following , not working:
sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); preferencemanager.setdefaultvalues(this, r.xml.settings, true); prefs.registeronsharedpreferencechangelistener(this);
if more information needed please let me know.
thanks in advance!
to reset preferences default values, need clear them first:
sharedpreferences prefs = preferencemanager.getdefaultsharedpreferences(this); prefs.edit().clear().commit(); preferencemanager.setdefaultvalues(this, r.xml.settings, true);
for more info, check out docs preferencemanager. discuss case when describing readagain
parameter of setdefaultvaules
:
note: not reset preferences default values. functionality, use getdefaultsharedpreferences(context) , clear followed call method parameter set true
Comments
Post a Comment