在我的登录和注销功能应用程序中,我正在检查活动开始时共享首选项是否为空,但我仍然收到 NullPointerException。
这是我的 HomeActivity.java 代码:
// Username And Password Editbox
String eusername;
String epassword;
// Shared Preferences String declaration
String spusername;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences spreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
spusername=spreferences.getString("spusername","");
if(!spusername.equals(""))
{
Log.e("Spusername not null","-->"+spusername);
}
if(spusername==null)
{
Log.e("Spusername null","-->"+spusername);
}
}