This Is The Code When I save My Value
public static final String
MyPREFERENCES = "MyPrefs" ;
public SharedPreferences sharedpreferences;
public static final String p = "pickLoc";
public static final String Phone = "dropLoc";
String pickLoc = pickupEt.getText().toString().trim();
String dropLoc = dropEt.getText().toString().trim();
sharedpreferences = getSharedPreferences(BookMyRide.this.MyPREFERENCES,
Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedpreferences.edit();
editor.putString(p, pickLoc);
editor.putString(Phone, dropLoc);
editor.commit();
This Is The Code When i Want to Get Value
try{
sharedpreferences = getSharedPreferences(MyPREFERENCES,Context.MODE_PRIVATE);
sharedpreferences.getString("pickLoc" ,"");
sharedpreferences.getString("dropLoc","");
}catch (Exception e){
e.printStackTrace();
}
Then it Throws the Exception :
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.SharedPreferences android.content.Context.getSharedPreferences(java.lang.String, int)' on a null object reference
Thanks In Advance For Helping Me