getInt()SharedPreferences android错误

BRK*_*BRK 1 android sharedpreferences

SharedPreferences peepsScores= PreferenceManager.getDefaultSharedPreferences(GamePlayFirst.this);
SharedPreferences.Editor editor =peepsScores.edit();

editor.putInt("userScore1", zero);
editor.putInt("userScore2", zero);
editor.putInt("userScore3", zero);
editor.putInt("userScore4", zero);
editor.putInt("userScore5", zero);
editor.putInt("userScore6", zero);
editor.putInt("userScore7", zero);
editor.putInt("userScore8", zero);
editor.commit();

SharedPreferences peepsScores = PreferenceManager.getDefaultSharedPreferences(this);
//tryed this
int userScore1 = peepsScores.getInt("userScore1","u");
//tryed this
userScore2 = peepsScores.getInt("userScore2","0");
//and tryed this
String userScore3 = peepsScores.getInt("userScore3","0");
String userScore4 = peepsScores.getInt("userScore4","0");
String userScore5 = peepsScores.getInt("userScore5","0");
String userScore6 = peepsScores.getInt("userScore6","0");
String userScore7 = peepsScores.getInt("userScore7","0");
String userScore8 = peepsScores.getInt("userScore8","0");
Run Code Online (Sandbox Code Playgroud)

getint方法有下划线,无论我改变什么随机的东西,然后如果我删除收到类的第一行peepScore加下划线我已经在Android开发网站这个网站和所有谷歌一切都说它就像getInt一样简单我在做什么错误

我试着弄清楚以后添加我想当我最终得到这个即时通讯发布这个所有像我这样的新人看到大声笑

Chi*_*rag 12

试试这个.

int userScore1 = peepsScores.getInt("userScore1",0);
Run Code Online (Sandbox Code Playgroud)

当您使用getInt时,如果您的值未在共享首选项中设置,则必须返回整数值.