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
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900

Application crashes while using the Custom Class

Hi 

I am created a  custom class extending the Thread class. And i am using that class in my constructor as:

 

public MyApp()

{

//AnimatedGifField

 

CustomThread thread = new CustomThread();

thread.start();

}

 

class CustomThread extends Thread

{

public void run()

{

//Openng the browser field here.While the document gets loaded.Deleting the animatedGifField and added the document.

 

synchronized (UiApplication.getEventLock())
{
manager2.delete(gifManager);
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.add(Catalogue.browserField);
manager2.add(vfm);
}

 

 

super.run();

}

}

 

But after sometime when the device goes into sleep state the application gets closed. What is the thing that causes the application crash??

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

Re: Application crashes while using the Custom Class

[ Edited ]

Can you explain in words, what this code is intended to do and why you think it is needed.  The code looks, well, weird, and I don't want to spend time debugging a bit of code that in fact is not needed or not doing the right job. 

Developer
robert30
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900

Re: Application crashes while using the Custom Class

Sir

I have to load the webpage from the server and display it in the browser implemented in the application.

Till the page is loading, i have added an animated gif image and when the page is loaded the manager in which the image is added is deleted and the browserfield is added to its place.

 

May i know why the code is wierd???

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: Application crashes while using the Custom Class

it makes no sense to use a thread for that.
----------------------------------------------------------
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
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Application crashes while using the Custom Class

I understand what the code is trying to do since you said that in the comments.  I was more concerned about the actions your code was taking to achieve this.  What is the processing involved - what does starting the Thread achieve, how do you know that the BrowserField has been loaded?  I see nothing in the code that actually indicates that it will achieve what you want.  So perhaps you could explain how your code was going to work? 

 

In fact I think the code is unlikely to be using the recommended approach to doing this.  I suggest searching before you try things that are new to you, you might for example have found this:

 

http://supportforums.blackberry.com/t5/Java-Development/After-loading-the-web-page-I-want-to-display...

 

One final thing.  Since I am not sure that you understand the full implications of using

"synchronized (UiApplication.getEventLock()) {

// Code to run on the Event Thread

}"

I recommend that instead you use

"UiApplication.getUiApplication().invokeLater(new Runnable() {

public void run() {

// Code to run on the Event Thread

}

});"