我试图在我的应用程序中实现高分功能,并且我创建了一个int分数变量,但是当我尝试在另一个类中调用它时,我总是收到“无法解析符号'得分了'”。Android Studio - 无法解析符号
int score = getIntent().getIntExtra("score", 0);
scoreLabel.setText(score + "");
SharedPreferences settings = getSharedPreferences("Game_Data", Context.MODE_PRIVATE);
int highScore = settings.getInt("High_Score", 0);
if(SystemClock.elapsedRealtime() > highScore){
highScoreLabel.setText("High Score : " + score);
//save
SharedPreferences.Editor editor = settings.edit();
editor.putInt("High_Score", score);
editor.commit();
}else {
highScoreLabel.setText("High Score : " + highScore);
}
}
然后我在下面的代码中调用函数,但变量'score'一直显示为不能解析符号。我能做什么?
Intent intent = new Intent(getApplicationContext(), scoreKeeper.class);
intent.putExtra("score", score);
startActivity(intent);
请记住我是初学者所以它可能是一些简单的,我已经错过了。 谢谢。
确保评分在您的课堂上设置为全局变量 – ZeroOne
保持变量e分数作为班级(全球)变量,如果两个代码在不同的方法 –
这个问题的任何更新? –