BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/)
-   Developer Forum (http://www.blackberryforums.com/developer-forum/)
-   -   Unable to set variable values inside the timer function (http://www.blackberryforums.com/developer-forum/219175-unable-set-variable-values-inside-timer-function.html)

MobileDeveloperUK 02-09-2010 12:07 AM

Unable to set variable values inside the timer function
 
Hi

i am utilising the timer event to get the value from a text box and storing it into a variable after saving the previous value onto another variable


Timer timer = new Timer();
TimerTask updateTask;

String prevEntry;
String crntEntry;



updateTask = new TimerTask() {

public void run() {


prevEntry = crntEntry;

crntEntry = field1.gettext();

}

}

where field1 is declared as BasicEditField

But I am getting errors like

local variable crntEntry is accessed from within inner class; needs to be declared final
prevEntry = crntEntry;
^

hrbuckley 02-09-2010 01:00 PM

OK, first read this please: http://www.blackberryforums.com/deve...rum-posts.html

That will make it much easier for us to help you.

Quote:

Originally Posted by MobileDeveloperUK (Post 1562188)
Hi

i am utilising the timer event to get the value from a text box and storing it into a variable after saving the previous value onto another variable

[snip]

where field1 is declared as BasicEditField

But I am getting errors like

local variable crntEntry is accessed from within inner class; needs to be declared final
prevEntry = crntEntry;
^

Code:

Timer timer = new Timer();
TimerTask updateTask;

 String prevEntry;
 String  crntEntry;

 
     
updateTask = new TimerTask() {
   
    public  void run() {

 
    prevEntry =  crntEntry;
 
    crntEntry = field1.gettext();
 
    }

}

updateTask is an instance of an inner class, as the compiler is telling you. It wants to be sure strange things won't happen such as another thread changing the value of prevEntry behind its back. However if you declare a variable as final you can't change it.

A little more context would help, surely preEntry and crntEntry don't exist as bar Strings like that, they must me members of some class. Do you have access functions defined for them?


All times are GMT -5. The time now is 12:29 AM.

Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.