SharedPreferences nullPointerException when saving strings

后端 未结 4 729
小鲜肉
小鲜肉 2021-01-26 10:50

I am working launcher for android. At the moment I am working for address book(yes I want to include it to my launcher), but I am getting NullPointerException. Here

4条回答
  •  醉话见心
    2021-01-26 11:12

    If you use editor.putString(number,button);, 'number' is your key and 'button' is your default value.

    If you want to retrieve the value of 'number' in your SharedPreferences, you should call getString(key, defValue) as follow :

    return pres.getString(number, "");

提交回复
热议问题