特定のスレッドについて、次のコードがあります
public void run() {
while (true) {
currentWord = words.get(new Random().nextInt(words.size()));
tvForeignWord.setText(currentWord.getWordForeign());
tvScore.setText("Your score is " + score);
for (int i = timer_length; i > 0; i--) {
tvTimer.setText("You have " + i + " seconds remaining.");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
//DEBUG e.printStackTrace();
}
}
}
}
ただし、次のエラー メッセージが表示されるようです。
02-19 22:03:38.950: E/AndroidRuntime(17236): android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
どうした?
代わりにこれを行うと:
public void run() {
//while (true) {
currentWord = words.get(new Random().nextInt(words.size()));
tvForeignWord.setText(currentWord.getWordForeign());
tvScore.setText("Your score is " + score);
//for (int i = timer_length; i > 0; i--) {
//tvTimer.setText("You have " + i + " seconds remaining.");
//try {
//Thread.sleep(1000);
//} catch (InterruptedException e) {
//DEBUG e.printStackTrace();
//}
//}
}
エラーが出ませんか?