I keep getting this error message
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long
I am trying to pass a long value between activities using shared preferences here is the code for my first activity
SharedPreferences sp = getApplicationContext().getSharedPreferences("userdata", Context.MODE_PRIVATE);
Calendar cal = Calendar.getInstance();
SharedPreferences.Editor editor = sp.edit();
editor.putLong("time"+i, cal.getTimeInMillis());
editor.commit();
here is my code for the second activity.
ArrayList<Long> time = new ArrayList<Long>();
sp = getSharedPreferences("userdata", Context.MODE_PRIVATE);
time.add(sp.getLong("time"+i,0)); // here is where the error occurs
The reason for the +i at the end of "time" is that these put and receive messages are running in for loops, because there are multiple longs that are being passed and the order matters. Please let me know if there is another way I should do this or how to resolve this exception.
Thank You