对于特定线程,我有以下代码
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();
//}
//}
}
我没有错误?