I am new to using shared preferences and on my first try im getting errors that don't make sense to me. I assign a value like this:
int saveScore = sp.getInt("SAVE_SPOT",0); //This is intentional to get the
//default value of 0 to go to case 0
switch(saveScore){
case 0:
SharedPreferences.Editor edit1 = sp.edit();
edit1.putInt("SCORE_1", score);
edit1.putInt("SAVE_SPOT", 1);
edit1.commit();
break;
case 1:
int previous_score = sp.getInt("SCORE_1",0); // error happens here
if(sp.getInt("SCORE_1",0)>score){
SharedPreferences.Editor edit2 = sp.edit();
edit2.putInt("SCORE_2", score);
edit2.putInt("SAVE_SPOT", 2);
edit2.commit();
}
else{
SharedPreferences.Editor edit3 = sp.edit();
edit3.putInt("SCORE_2", previous_score);
edit3.putInt("SCORE_1", score);
edit3.putInt("SAVE_SPOT", 1);
edit3.commit();
}
break;
Every time i run the program i get the error "string cannot be cast to integer". I am almost 99% sure the variable score is an int and not a string but I am not sure why i am getting this error.