I searched for quite some time and to no avail as I still don't know why it's not working.
I am already using SharedPreference between one Activity and another
Code:
Saving Data
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("email", email.getEmail().toString());
editor.apply();
Retrieving Data
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
String userEmail = preferences.getString("email", "defaultValue");
DisplayEmail.setText(userEmail);
This code is working fine. But now, when moving on to the other shared preference, this happens:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.nathan.application/com.example.nathan.application.ActCamera}: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2796) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2867) at android.app.ActivityThread.-wrap12(ActivityThread.java) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1570) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:156) at android.app.ActivityThread.main(ActivityThread.java:6595) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832) Caused by: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
The code due to this error:
double Latitude = loc.getLatitude();
double Longitude = loc.getLatitude();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = preferences.edit();
editor.putString("Country", details.doInBackground().toString());
editor.putLong("Latitude", Double.doubleToRawLongBits(Latitude));
editor.putLong("Longitude", Double.doubleToRawLongBits(Longitude));
editor.apply();
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
Latitude = Double.longBitsToDouble(preferences.getLong("Latitude", 0));
Longitude = Double.longBitsToDouble(preferences.getLong("Longitude", 0));