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: 19
Registered: ‎11-25-2009
My Device: Not Specified

Exception:: pushGlobalScreen(modal) called by a non-event thread

I am getting "pushGlobalScreen(modal) called by a non-event thread" exception although putting pushGlobalScreen in every different thread. any help???

 

here is the code::


  invokeAndWait(new Runnable() {
   public void run(){
    System.out.println("Inside Get and Post readings");
    UiEngine ui = Ui.getUiEngine();
    System.out.println("After ui getengine");
    ReadingTypesScreen rdscrn = new ReadingTypesScreen();
    System.out.println("After instantiating ReadingTypesScreen object");
    ui.pushGlobalScreen(rdscrn, 1,0);
    System.out.println("Screen selected ="+ rdscrn.screen_name);
    current_screen = rdscrn.screen_name;
      }
  });
  invokeAndWait(new Runnable() {
   public void run(){
    if(current_screen == "BS")
    {
     invokeAndWait(new Runnable(){
      public void run(){ 
       UiEngine ui = Ui.getUiEngine();
       BSScreen  bs = new BSScreen();
       ui.pushGlobalScreen(bs, 1, GLOBAL_MODAL);
       System.out.println("Data to be posted =" + bs.sendData);  
       String reply;
       reply = Util.HTTPPost("http://www.happyhippoinc.com/blood_sugars",bs.sendData);
       System.out.println("Reply from post ="+ reply);

      }
     });
    }
   }
  });

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

Re: Exception:: pushGlobalScreen(modal) called by a non-event thread

I'm not able to follow this code.

 

Does the app extend UiApplication?  Have you entered the event dispatcher?

 

If so, then why are you trying to get the UI Engine to push the screen? All you have to do is call pushGlobalScreen().

 

Also, why are you trying to push a global-modal if you have a UiAplication that is in the foreground? Just call pushModalScreen().

 

If this code is not really in the Ui Event thread, this would have to be UiApplication.getUipplication().invokeAndWait().

 

Sorry, I'm very confused.  Maybe if you just tell us what you are trying to accomplish?

 

 

 

 

New Developer
Posts: 19
Registered: ‎11-25-2009
My Device: Not Specified

Re: Exception:: pushGlobalScreen(modal) called by a non-event thread

sorry am new to BB development..

 

am writing a foreground app..it does extendts uiapplication and enters the event disptacher..

 

i have replaced all ui.pushGlobalscreen instances with pushModalScreen(screen_name)...

 

am still getting the exception PushModalScreen called by a non event thread..pls help

 

 

here is the code::

 

 

 

public final class MainApp extends UiApplication
{


 private void GetAndPostReadings()
 {
  invokeAndWait(new Runnable() {
   public void run(){
    System.out.println("Inside Get and Post readings");
    //UiEngine uie = Ui.getUiEngine();
    //System.out.println("After uie getengine");
    ReadingTypesScreen rdscrn = new ReadingTypesScreen();
    System.out.println("After instantiating ReadingTypesScreen object");
    //uie.pushGlobalScreen(rdscrn, 1, GLOBAL_MODAL);
    //pushGlobalScreen(rdscrn,1,GLOBAL_MODAL);
    pushModalScreen(rdscrn);
    System.out.println("Screen selected ="+ rdscrn.screen_name);
    
    if(rdscrn.screen_name == "BS")
    {
     invokeAndWait(new Runnable(){
      public void run(){ 
       //UiEngine ui = Ui.getUiEngine();
       BSScreen  bs = new BSScreen();
       //ui.pushGlobalScreen(bs, 1, GLOBAL_MODAL);
       pushModalScreen(bs);
       System.out.println("Data to be posted =" + bs.sendData);  
       String reply;
       reply = Util.HTTPPost("http://www.happyhippoinc.com/blood_sugars",bs.sendData);
       System.out.println("Reply from post ="+ reply);


      }
     });
    }
   }
  });

 }


 public static void main(String[] args)
 {
  MainApp theApp = new MainApp();
  theApp.enterEventDispatcher();
 }

 public MainApp()
 {
  try
  {
   
   GetAndPostReadings();
   
   invokeAndWait(new Runnable()
   {
    public void run(){               
     //UiEngine ui = Ui.getUiEngine();

     Screen screen = new Dialog(Dialog.D_OK, "Data saved! " ,
       Dialog.OK, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),  
       Manager.VERTICAL_SCROLL);
     //pushGlobalScreen(screen, 1, GLOBAL_MODAL);
     pushModalScreen(screen);


     System.exit(1);


    }
   });
  }
  catch(Exception e)
  {
   System.out.println("Some Exception" + e.getMessage());
  }

  
 }
}

 

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

Re: Exception:: pushGlobalScreen(modal) called by a non-event thread

You absolutely have to get rid of all this "invokeAndWait" stuff. I cannot see a purpose for it here.

 

PLEASE...look at the sample HelloWorld application that ships with the JDE.