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: 37
Registered: ‎05-05-2009
My Device: Not Specified

White Screen

I have just created a new project nothing in it but the code below, but all I get is a white screen.  Anybody any idea what is going on here?

 

 

package TestP;

import net.rim.device.api.ui.*;


public class Main extends UiApplication {

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		Main app = new Main();
		app.enterEventDispatcher();
	}

	// Constructor
	Main()
	{        
		FrontScreen fs = new FrontScreen();
		pushScreen (fs);
	}

}



package TestP;

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

public class FrontScreen extends MainScreen {

	public FrontScreen()
	{
        //title at the top
    	LabelField lb = new LabelField("Hello", Field.FIELD_VCENTER | Field.USE_ALL_WIDTH | DrawStyle.HCENTER);

		this.setTitle(lb);

	}
	
}

 I've tried adding various Fields to the screen, all with the same effect, i.e. just a white screen.  I am using eclipse as the IDE.

 

Thanks,

 

Slicc

 

Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: White Screen

Push the screen after you have entered the event thread.

 

Any reason for not calling super() of your MainScreen ?

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: White Screen

I just ran your code and got a screen with a nice "Hello" title bar. Are you running this from within Eclipse? What JDE version and what simulator are you using?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
New Developer
Posts: 37
Registered: ‎05-05-2009
My Device: Not Specified

Re: White Screen

Thanks both, I have now managed to fix the problem by going to (in eclipse) BlackBerry->Build Configuration->edit  and there checking release and  debug, neither were checked.

 

Slicc

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: White Screen

@dnepr - the call to enterEventDispatcher() never returns. A screen needs to be pushed before entering the event thread. Also, the only time you need to explicitly call super() is to pass arguments to the superclass constructor; if there is no call to super(), then the compiler automatically inserts a call to the no-argument superclass constructor.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: White Screen

[ Edited ]

You don't need to have a screen on the stack before entering the dispatch thread.   Its a preference thing I suppose.

 

Not sure where that "not returns" thing came from, I never said it did...

 

Calling super() is cleaner code imo.

 

Developer
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: White Screen

Since enterEventDispatcher() never returns, I can only think of three ways to push a screen after entering the event thread:

  1. start a worker thread from main() that will call invokeLater() to push the screen
  2. call invokeLater() in main() (or something called by main()) before calling enterEventDispatcher()
  3. queue some other event that will dispatch to your code to push the screen after event processing starts.

All those seem unnecessarily baroque compared to just pushing the screen (like slicc's code was doing) before entering the event dispatch loop. But perhaps you had something else in mind.

 

Also, what do you mean by "cleaner code"? It just seems like clutter to me, akin to putting "this." in front of every field and method reference.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Highlighted
Developer
Posts: 723
Registered: ‎03-12-2009
My Device: Playbook

Re: White Screen

[ Edited ]

That may be, but it doesn't "need" to be done.

 

edit:

 

You are probably right, not arguing with you.