BlackBerry Forums Support Community
              

Closed Thread
 
LinkBack Thread Tools
Old 02-09-2010, 01:07 AM   #1 (permalink)
Thumbs Must Hurt
 
Join Date: Jan 2010
Model: 8300
PIN: N/A
Carrier: T-Mobile
Posts: 62
Post Thanks: 1
Thanked 0 Times in 0 Posts
Default Unable to set variable values inside the timer function

Please Login to Remove!

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;
^
Offline  
Old 02-09-2010, 02:00 PM   #2 (permalink)
BlackBerry Extraordinaire
 
Join Date: Jan 2006
Model: LEZ10
OS: 10.0.10
Carrier: Rogers CA
Posts: 1,704
Post Thanks: 20
Thanked 77 Times in 68 Posts
Default

OK, first read this please: How to paste 100% FORMATTED Source Code In Your Forum Posts

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

Quote:
Originally Posted by MobileDeveloperUK View Post
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?
__________________
My other Blackberry is a PlayBook.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Used Mobile Celeron N2940 SR1YV CPU 4 Cores FH8065301919600
$25.8
Used  Mobile Celeron N2940 SR1YV CPU   4 Cores FH8065301919600 pictureUsed Mobile Celeron N2830 SR1W4 CPU FH8065301729602
$19.8
Used  Mobile Celeron N2830 SR1W4 CPU  FH8065301729602 pictureAllen Bradley PLC CPU L35E & 1769-PA4 Stack w/ IQ16, OW16. IF8 x2,OF8C x2 & PS
$749.0
Allen Bradley PLC CPU L35E & 1769-PA4 Stack w/  IQ16, OW16. IF8 x2,OF8C x2 & PS pictureOmron CQM1H-CPU51 PLC Module PA203
$600.0
Omron CQM1H-CPU51 PLC Module PA203 pictureSIEMENS S7 1200 CPU 1214 C PN AC DC RLY 6ES7 214 1BE30 0XB0
$328.0
SIEMENS S7 1200 CPU 1214 C PN AC DC RLY 6ES7 214 1BE30 0XB0 picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.