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

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -