SharedPreferences nullPointerException when saving strings

后端 未结 4 760
小鲜肉
小鲜肉 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:27

    You can declare ShardPreference object twice. 1. class level 2. in adNumber().

    so, please remove one of that and declare like this with initiate.

    SharedPreferences pres = getApplicationContext().getSharedPreferences("MyPres", MODE_PRIVATE); 
    

    and used it anywhere is you declare it on class level.

提交回复
热议问题