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
New Developer
Posts: 15
Registered: ‎12-20-2009
My Device: Not Specified
My Carrier: Sprint
Accepted Solution

Odd Screens RuntimeException

Using Eclipse, targeting 8330 devices and better, OS 4.5 & better...

 

import java.util.Vector;
import net.rim.device.api.ui.UiApplication;

public class ScreensApp extends UiApplication {

	public static Vector screenV;
	
	public ScreensApp() {
		screenV = new Vector();
		pushScreen( new Screens2() );
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ScreensApp app = new ScreensApp( );
		app.enterEventDispatcher(); //point of no return
	}

}

 

import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;

public class Screens2 extends MainScreen {

		public Screens2() {
			
			if (ScreensApp.screenV.isEmpty()) {
				try {
					Dialog.alert("screenV is empty!");
				} catch ( RuntimeException e) {
					System.out.println(  e.toString() );
				}
			}
			
			LabelField label = new LabelField( "screens2 label" );
			add( label );
			
		}
}

 These two classes are the essense of a problem I'm running into.  I'm trying to develop a simple, single-threaded (no network requirements) application. The Dialog throws a RuntimeException[1] and I don't know why.  Since Screens2  is being pushed onto the screen stack from ScreensApp and not running in parallel with ScreensApp, I thought it ran on the event thread and I wouldn't need to use syncronize or invokelater to get the Dialog alert to display.  If this is wrong, can someone please clarify why (and how) this has become a multi-threaded application (or what ever else is happening to cause the RuntimeException)? thank you in advance!

 

[1] The error is "java.lang.RuntimeException: pushModalScreen called by a non-event thread"

 

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Odd Screens RuntimeException

[ Edited ]

Your issue is that you are attempting to instantiate a modal dialog (your alert dialog) from the constructor of the Screens2 class. At the time that this constructor is executing, the application has not yet entered the event dispatcher.

 

The app does not enter the event dispatcher until after the Screens2 object is instantiated.  Get rid of the Dialog.alert here in the constructor.

 

 

 

New Developer
Posts: 15
Registered: ‎12-20-2009
My Device: Not Specified
My Carrier: Sprint

Re: Odd Screens RuntimeException

RexDoug,

 

Thanks for the explaination.  I'd been struggling with this for a while.

 

Best regards!

Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Odd Screens RuntimeException

How do you display a message for the user (or for testing) in this situation?  Do you have to create a text field for that?  Or is there another way?

Developer
Posts: 4,764
Registered: ‎07-21-2008
My Device: Not Specified

Re: Odd Screens RuntimeException

[ Edited ]

You cannot display any type of UI component until you enter the dispatcher.

 

Exactly which "situation" are you refering to?

 

Also, please refrain from posting new questions in solved threads.

 

Highlighted
Developer
Posts: 113
Registered: ‎09-30-2009
My Device: Bold 9700

Re: Odd Screens RuntimeException

Any kind of error/exception, and also testing messages.