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
Highlighted
New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon
Accepted Solution

A little help with coding. Can someone explain why my GUI doesn't work?

Hello everyone, I'm currently developing a simple app for a 9930 device and I'm running into a litttle bit of an issue.  I downloaded some code that was supposedly developed by blackberry called the Emergency Contact List.

 

Here is my issue:  The gui isn't popping up when the app runs.  I believe that the code is simple enough so that you may help me figure out this issue.

 

The source code can be found here: http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/796557/800451/1055819...

 

 

 

However,  here is my short version of the code just so that you can see what I'm doing.

 

This is the the file that contains main().  The first condition of the if statement just creates a GUI and displays it onto the screen.

 

    /**
     * <description> Starts the push data listener intially
     * @param args <description>
     */
       
    public static void main(String[] args) {
        if( args != null && args.length > 0) {
            ECLApplication theApp = new ECLApplication();
            theApp.enterEventDispatcher();
        }
        else {
   
            PushedDataListener.waitForSingleton().start();

        }
    }

 

Well, of course the inital argument is null and the length is certainly not greater than 0 so we invoke the static function "waitForSingleton".

 

/******************************************************************************************
* BackGround waitForSingleton() - returns an instance of a listening thread
******************************************************************************************/       
    public static PushedDataListener waitForSingleton(){
        //make sure this is a singleton instance
        RuntimeStore store = RuntimeStore.getRuntimeStore();
        Object o = store.get(RTSID_MY_APP);
        if (o == null){
            store.put(RTSID_MY_APP, new PushedDataListener());
            return (PushedDataListener)store.get(RTSID_MY_APP);
        } else {
            return (PushedDataListener)o;
        }
    }

 

returns the instance of the PushDataListener.

 

And now we invoke the start() method.

 

/******************************************************************************************
* start() - starts the custom listen thread
******************************************************************************************/    
    public void start(){
        invokeLater(new Runnable() {
            public void run() {
                myThread.start();
                
                //NotificationsManager.registerSource(ID_1, event, NotificationsConstants.CASUAL);//registring the object event to profiles
            }
        });
        
        this.enterEventDispatcher(); 
    }

 

The program gets stuck at

this.enterEventDispatcher(); 



From my understanding, enterEventdispatcher() is suppose to invoke all event handlers and drawings(GUI).

 

What am I doing wrong?

 

The debug call stack says that it is waiting?

 

 

Please help! I've been stuck on this issue for a week now!

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

Re: A little help with coding. Can someone explain why my GUI doesn't work?

 Every app "gets stuck" at enterEventDispatcher() - this does not return until the app exits.

 

My guess here is that you were supposed to add a parameter to one of the entry points. Usually this is something like "GUI" to start the GUI.

 

New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon

Re: A little help with coding. Can someone explain why my GUI doesn't work?

Please elaborate on "entry point"  I'm new to blackberry development so this is pretty foreign to me.

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: A little help with coding. Can someone explain why my GUI doesn't work?

The function enterEventDispatcher() is not suppose to return.

 

Before calling this function you should have some code which pushes a screen onto the stack in order to display your GUI.

 

Or, you should put your application to background and wait for an event (push) that will activate you your application and return it to the foreground.

 

E.

New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon

Re: A little help with coding. Can someone explain why my GUI doesn't work?

How do you store and access the stack?

Developer
Posts: 729
Registered: ‎05-04-2011
My Device: 9700

Re: A little help with coding. Can someone explain why my GUI doesn't work?

You don't manage the display stack on your own.

 

You can push/pop screens using the UiApplication or UI classes.

 

However, I suggest you refer to the documentation and sample applications for more info first.

 

E.

New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon

Re: A little help with coding. Can someone explain why my GUI doesn't work?

Are you able to link me to a good example?  all the other examples don't seem to have one with 2 items that will have to run concurrently.  All the examples seems to just have the GUI displayed.

New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon

Re: A little help with coding. Can someone explain why my GUI doesn't work?

class ECLApplication extends UiApplication {


    private MenuItem _display1;
    private MenuItem _information;
    private MenuItem _addContact;
    DataStore dataStore;
    ObjectListField list= new ObjectListField(); 
    ObjectListField AllContacts = new ObjectListField();
    EclStore contactList;
    DisplayScreen screen2;
    int location;
    FindContact ContactLocation = new FindContact();
    /******************************************************************************************
    * main() - controls the startup of the application...thread will start in the background
    *           and the GUI starts when user clicks from main menu
    ******************************************************************************************/ 
    /**
     * <description> Starts the push data listener intially
     * @param args <description>
     */
       
    public static void main(String[] args) {
        if( args != null && args.length > 0) {
            ECLApplication theApp = new ECLApplication();
            theApp.enterEventDispatcher();
        }
        else {
            PushedDataListener.waitForSingleton().start();

        }
    }

 

 

Ok, now.  I know that this thread is suppose to run indefinitely as long as the phone is on. 

 

Is it possible that this is SUPPOSE to be the scenario? 

1.  This app is suppose to run automatically at startup of the blackberry device so that the datalistener thread can run.

2.  When the user clicks on the app, it goes into the first condition to show the gui while the datalistener is in the background trying to keep the gui inform and updates it when necessary. 

 

This application has worked on older devices and is having trouble on the 9930. 

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

Re: A little help with coding. Can someone explain why my GUI doesn't work?

Correct, but it won't happen unless you have set up the "GUI" parameter in the main entry point.

 

So basically, when the user clicks on the icon, it starts the app *with* the GUI parameter. When started by the system, the parameter is not passed.

 

These parameters are in your BB project setup.

New Developer
Posts: 19
Registered: ‎10-17-2011
My Device: bold 9930
My Carrier: verizon

Re: A little help with coding. Can someone explain why my GUI doesn't work?

I will give this a try and let you know the results!  Thanks!  I didn't think of the parameter.