Reputation: 11
I am trying to do create an android application that updates an image based on information that has been received. In the onCreate method of my main activity I am trying to use the following code to constantly update as the app runs. Currently there is an error with the runnable I have marked below (bolded or with **). It says, "runnable may not have been initialized". I was wondering how to to fix this.
final int delayMs = 1000;
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override public void run() {
// Call your refresh method
Refresher();
// Restart the timer
handler.postDelayed(**runnable**, delayMs);
}
};
handler.postDelayed(runnable, delayMs);
Upvotes: 1
Views: 503
Reputation: 1
It is not clear what is it you what to achieve by this? Could you provide more code here? Answering your exact question here, you are trying to use reference to your final 'runnable' variable inside Runnable implementation and it isn't clear that 'runnable' was initialized on time of use.
Upvotes: 0
Reputation: 317467
Define runnable
as a member of the enclosing class instead of as a local variable inside the same method where it's used.
Upvotes: 1