0

I am trying to push the screen on may main UiApplication (MyApp) based on the either database is created or not and if its created than is it emapty or is it having some data.. but when i run this code my balckberry application jsts hangs ..

any help is appreciated :)

i have checked that the virtual SDCard is there in simulator and i have even code to check at runtime whether SDCard is avialable or not.

  • JDE Version 6.0 with Eclipse Helios

  • plug in BlackBerry Simulator : 9800

  • Os : windows 7 32 bit ultimate edition

below is my code that i am using in my app

public MyApp()
    {   

        try {
                MyAppURI  = URI.create("file:///SDCard/BlackBerry/Database/"
                        + "MyApp.db");
                this.setMyURI(MyAppURI);

                boolean flag = false;
                flag = DatabaseFactory.exists(getMyURI());
                if ( flag == false){
                    db = DatabaseFactory.create(getMyURI());
                    db.close();
                    new DatabaseSchema(); // this will simpaly create setting table in databse MyApp.db i am closing the database there
                    pushScreen(new Settings());
                }else{
                    db = DatabaseFactory.open(getMyURI());
                    Statement st = db.createStatement("select count(*) from Setting");
                    Cursor cursor = st.getCursor();
                    if (cursor.isEmpty() == true){
                        pushScreen(new Settings());
                    }else{
                        pushScreen(new Reports());
                    }               
                }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
MrPandav
  • 1,831
  • 1
  • 20
  • 24
  • 2
    If you comment out all the code in the MyApp and only leave the `pushScreen(new Settings());` line, then does it work? – Vit Khudenko Apr 21 '11 at 09:33

1 Answers1

2

Ideally you should be running these database operations in their own Thread, as they are blocking operations. One thing that I've found helpful is to put my pushScreen()s in invokeLater() calls when I'm pushing them from a constructor if they aren't displaying properly. This allows the system to finish anything that needs to be done prior to displaying a Screen, and then it will be able to push.

jprofitt
  • 10,874
  • 4
  • 36
  • 46