Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 16,786
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: How to refresh screen with http call automatically?

inside processData you don't have access to the thread. you should give the result as a parameter to the method.
in the method you use invokelater to update the UI.

(you do not need invokelater in the constructor of the screen)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 96
Registered: ‎06-05-2012
My Device: Developer
My Carrier: Developer

Re: How to refresh screen with http call automatically?

Hi,

you should use below code inside your network thread:

UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
// Update Screen
}
});
Thanks,
Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: How to refresh screen with http call automatically?

[ Edited ]

But the rest was fine then? I've implemented your suggestions but the NullPointerException still occurs when I call the processData method (the arguments should be fine)

 

public interface ConnectionCallback {

	public void processData(String[][] prArrays, int prResultLength);
	
}
ConnectionCallback callbackObj;
	
	public ConnectionThread(ConnectionCallback conCallback) {
		callbackObj = conCallback;

                  //http call

                  callbackObj.processData(anwendungArrays, resultLength); 
         }

 

ConnectionThread conThread;
MyScreen myScreen; public MyScreen() { conThread = new ConnectionThread(myScreen); conThread.start(); // paint screen } public void processData(String[][] prArray, int prResultLength) {  anwendungArrays = prArray; resultLength = prResultLength; UiApplication.getUiApplication().invokeLater(new Runnable() { public void run() { UiApplication.getUiApplication().pushScreen( new MyScreen()); } }); }

 

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to refresh screen with http call automatically?

And the NPE is where?

Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: How to refresh screen with http call automatically?

Sorry, still at the same line of the ConnectionThread:

 

  callbackObj.processData(anwendungArrays, resultLength);

 

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to refresh screen with http call automatically?

If it happens there, the only thing that it looks like can be null is callbackObj.  I would debug, and/or add a check to make sure it is not null.

Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: How to refresh screen with http call automatically?

Seems so.. the arguments are definitely fine.

 

The check says the myScreen object is null, but when I initialize it before

 

MyScreen myScreen = new MyScreen(); 

 the app runs out of memory and doesn't display the screen.

Developer
Posts: 19,631
Registered: ‎07-14-2008
My Device: Not Specified

Re: How to refresh screen with http call automatically?

Looks like you have some sort of logic error in your processing, you are not doing things in the correct order.  I suggest you use the debugger to step through your code to confirm the order of processing.

 

If your are running out of memory, then that indicates you have a loop, For example,  when you "a" it does "b", when you do "b" it does "c" and when you "c" it does "a", which starts the whole process again...  Debugging should sort that out to. 

 

Perhaps this will help:

http://supportforums.blackberry.com/t5/Java-Development/Debug-using-the-BlackBerry-Java-Plug-in-for-...

Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: How to refresh screen with http call automatically?

Got it finally! Like most of the times there was just one single thing missing ;-) The myScreen object was null so I just had to add

 

myScreen = this; 

 inside the constructor Smiley Wink

 

Thank you all for your help!!

Cheers, Musipoo

 

Contributor
Posts: 41
Registered: ‎02-04-2013
My Device: Bold 9900
My Carrier: Vodafone

Re: How to refresh screen with http call automatically?

After a while I figured out the processing of the data works out but something is still going wrong with the threads.. the main screen freezes after getting the data and there is no more interaction possible so I have to close the whole simulator.
Every time I get new data I push the main screen again, where also a new http call thread is being started - is it possible that this crashes the app?