そのコードに問題があります
setContentView(R.layout.game);
TextView text = (TextView) findViewById(R.id.qwe_string);
text.setText("Hello Android");
アクティビティ内にある場合は機能しますが、そうでない場合は、明らかにエラーが発生します。
The method findViewById(int) is undefined for the type new TimerTask(){}
The method setContentView(int) is undefined for the type new TimerTask(){}
コードは別のクラス(アクティビティではない)のタイマー内にあります。完全なコードは次のとおりです。
//main timer task for ingame time processing
static Timer gameTimer = new Timer();
static TimerTask gameTimerTask = new TimerTask() {
@Override
public void run() {
setContentView(R.layout.game);
TextView text = (TextView) findViewById(R.id.qwe_string);
text.setText("Hello Android");
}
};
そのように変えてみました
ScreenGame.this.setContentView(R.layout.game);
TextView text = (TextView) ScreenGame.this.findViewById(R.id.qwe_string);
text.setText("Hello Android");
しかし、それでも機能しません:(
PS-はい、私は他の同様の質問を検索しましたが、それらはすべて同じように見えますが、実際には完全に異なります。