In a certain Activity have a TextView
variable named timeText, which needs to be changed after 3 seconds have passed after the Activity was opened.
This is the code I wrote:
TextView timeText = (TextView) findViewById(R.id.tvTimeText);
Thread timer = new Thread() {
public void run() {
try {
sleep(3000);
timeText.setText("3");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
timer.start();
However this gave me this error: "Cannot refer to a non-final variable timeText inside an inner class defined in a different method"
So I changed the modifier of the TextView
to final
and tried again.
However, now the application crashes when this activity is started.