java - SharedPreference clear() throwing nullpointerexception -



java - SharedPreference clear() throwing nullpointerexception -

i'm trying clear list, need clear sharedpreference. on doing so, nullpointerexception. here's code. -

mainactivity.savedlogname.edit().clear().commit(); mainactivity.savedlognumber.edit().clear().commit(); mainactivity.savedlogtime.edit().clear().commit();

i've tried using remove(), same error persists. here's code using remove()

mainactivity.savedlogname.edit().remove("logname").commit(); mainactivity.savedlognumber.edit().remove("lognumber").commit(); mainactivity.savedlogtime.edit().remove("logtime").commit();

note - savedlogname, savedlognumber , savedlogtime static variables declared in mainactivity. i'm calling them different activity class.

from mainactivity -

savedlogname = preferencemanager.getdefaultsharedpreferences(this); savedlognumber = preferencemanager.getdefaultsharedpreferences(this); savedlogtime = preferencemanager.getdefaultsharedpreferences(this); logname = new arraylist(arrays.aslist(textutils.split(savedlogname.getstring("logname", null), ","))); lognumber = new arraylist(arrays.aslist(textutils.split(savedlognumber.getstring("lognumber", null), ","))); logtime = new arraylist(arrays.aslist(textutils.split(savedlogtime.getstring("logtime", null), ",")));

i want logname, lognumber , logtime intialized null if sharedpreference empty. doesn't happen. initializes old values never cleared.

context.getsharedpreferences("your_prefs", 0).edit().clear().commit();

remove prefs

or editor , clear this

editor.clear(); editor.commit();

java android nullpointerexception

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -