BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-17-2010, 10:51 AM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
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 (permalink)
BlackBerry Extraordinaire
 
Join Date: Mar 2008
Location: Austin, TX
Model: 9700
PIN: N/A
Carrier: T-Mobile
Posts: 1,644
Post Thanks: 0
Thanked 34 Times in 33 Posts
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 (permalink)
Knows Where the Search Button Is
 
Join Date: Jun 2010
Model: 8530
PIN: N/A
Carrier: Sprint
Posts: 48
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you Dougsg38p. It worked now.
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





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