下面提供的这段代码中的朋友,我想在从播放意图恢复时刷新我的文本视图。但是,每当我尝试在 OnCreate 之外但在我的主类中定义我的 textview 时(在静态 int 分数之后),我的应用程序就会崩溃。
public class MainProjectActivity extends Activity {
/** Called when the activity is first created. */
static int Score = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//Display Scores
final TextView displayScores = (TextView)findViewById(R.id.scoreDisplay);
displayScores.setText("Your Score : "+ Score);
//Play Game button activity
Button gameButton = (Button)findViewById(R.id.PlayButton);
gameButton.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent play = new Intent(getApplicationContext(), com.sample.game.PlayScreen.class);
startActivity(play);
}
});