BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 08-17-2010, 10:51 AM   #1
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default Refreshing the screen not working

Please Login to Remove!

Refreshing the screen not working

Code:
public class MyScreen extends MainScreen{
private Timer headerTimer = new Timer();
private TimerTask headerTask;
 
public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
objList=srv.getList();//calls webmethod getList()
myMgr.add(objList)
add(myMgr);

headerTask= new TimerTask() {

public void run() {

 //doPaint();

 invalidate();
}
};

 headerTimer.scheduleAtFixedRate(headerTask, 3000, 3000);
}
}
There is no problem in displaying the data from the database. I am trying to refresh this screen data in every 3 seconds so that if any data change in database also reflect in this screen. But it doesn't work.

Also this screen is pushed from another screen using
net.rim.device.api.ui.UiApplication.getUiApplicati on().pushScreen(new MyScreen());

Please someone help me.

Last edited by romah; 08-17-2010 at 11:06 AM..
Offline  
Old 08-17-2010, 11:56 AM   #2
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

You cannot access the UI classes from a non-event thread (as you are doing here). The UI is non re-entrant.

Look at UiApplication.invokeLater() - this places your UI method calls in the event queue.
Offline  
Old 08-17-2010, 02:27 PM   #3
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

How to define 3 seconds time interval in UiApplication.invokeLater() so that it refreshs the screen repeatedly?

UiApplication.getUiApplication().invokeLater (new Runnable() {
public void run()
{
//Thread.sleep(3000);
invalidate();
}
});
Offline  
Old 08-17-2010, 02:57 PM   #4
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

I also tried with following code. Again, it's not working.

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
invalidate();
}
},3000,true);
Offline  
Old 08-17-2010, 05:15 PM   #5
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

What are you invalidating? If you are adding items to a listfield (for example) then you should be invalidating the list field.

Looks like you are trying to invalidate the screen here.
Offline  
Old 08-18-2010, 02:40 PM   #6
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

I added the object list in Manager and that mananger to the screen.
I tried invalidating the manager. Again it's not refreshing the screen data.

public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
ObjectListField objList=srv.getList();//calls webmethod getList()
myMgr.add(objList)
add(myMgr);

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
myMgr.invalidate();
}
},3000,true);
}
Offline  
Old 08-18-2010, 04:20 PM   #7
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

Now the refresh is working fine but throws exception while assigning the value to the manager in run().

public MyScreen() {

//some codes to display the data from database
VerticalFieldManager myMgr=new VerticalFieldManager();

myMgr=displayInfo();
add(myMgr);

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {

//invalidate();
myMgr=displayInfo();
myMgr.invalidate();
}
},3000,true);
}

public VerticalFieldManager displayInfo() {

VerticalFieldManager test=new VerticalFieldManager();
MySoap_Stub srv = new MySoap_Stub();//webservice object
ObjectListField objList=srv.getList();//calls webmethod getList()
test.add(objList)

retrun test;

}
Offline  
Old 08-18-2010, 05:01 PM   #8
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

I don't understand this code:

VerticalFieldManager myMgr=new VerticalFieldManager();
myMgr=displayInfo();

Why would you set myMgr to one value, then set it to another on the next line?

Then again:

myMgr=displayInfo();
myMgr.invalidate();

What is the point of assigning this variable yet again?

Exactly what line of code is throwing the exception?

My opinion, you need to rethink what you are doing here (either that, or I'm an idiot because I don't understand your code).

..could go either way...

Last edited by Dougsg38p; 08-18-2010 at 05:03 PM..
Offline  
Old 08-19-2010, 09:01 AM   #9
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

Code:
VerticalFieldManager myMgr=new VerticalFieldManager();
myMgr=displayInfo();
add(myMgr);
In above code, displayInfo() calls webmethod, populates the list with database values, adds the list in manager and returns manager which contains that list.
I assigned return value of displayInfo() to the another manager. And after that I added the manager to the screen.
This portion works fine for me.

I want to refresh the list in the manger in every 3 seconds. So, I tried to populate the manager with new values and invalidate the manager. But their is problem in assigning the return value of displayInfo() in the manager.

myMgr=displayInfo(); line throws exception [IllegalArgumentException] in code below.

Code:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
myMgr=displayInfo();
myMgr.invalidate();
}
},3000,true);
}
Offline  
Old 08-19-2010, 09:15 AM   #10
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

Woked fine !!! Solved !!!
Thank you Dougsg38p for helping me.

Code:
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
delete(myMgr);
myMgr=displayInfo();
add(myMgr);
myMgr.invalidate();
}
},3000,true);
Offline  
Old 08-19-2010, 09:15 AM   #11
Dougsg38p
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Default

The issue is not in the assignment of the value to myMgr.

Have you single-stepped the code to see where the error really is? Have you looked at the stack trace?

My guess is that you are adding the same field to the display twice, which would cause this error. There should be text assoicated wtih the exception, like "child already parented", or something like this.
Offline  
Old 08-19-2010, 09:17 AM   #12
romah
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Default

Thank you Dougsg38p. It worked now.
Offline  
Closed Thread



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet  picture

OEM iPhone 11 PRO X/XR XS MAX 8/7 PLUS Fast Charging USB Cable 10 Feet & 6 Feet

$2.99



iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M picture

iPhone 13 12 11 PRO MAX XR XS 8/7/6 Fast Charger USB Data Cable cord 10 feet/3M

$4.99



3M/10 feet Long Apple iPhone 13 12 11 Pro XS MAX XR X 8 Fast Charging Data Cable picture

3M/10 feet Long Apple iPhone 13 12 11 Pro XS MAX XR X 8 Fast Charging Data Cable

$3.50



10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord picture

10 Foot/3M iPhone 12/11 PRO MAX X/10 XR XS 8/7 FAST Charging USB LONG Cable cord

$4.98



Welch Allyn Standard (bulb) MAC 2 Laryngoscope Blade #69042 New in OEM Box picture

Welch Allyn Standard (bulb) MAC 2 Laryngoscope Blade #69042 New in OEM Box

$19.77



18 x Sunmed Macintosh Standard (Lamp) Laryngoscope Blades, Size 2, OEM ~17016 picture

18 x Sunmed Macintosh Standard (Lamp) Laryngoscope Blades, Size 2, OEM ~17016

$129.99







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