开发者

trouble pushing screen on Blackberry UIapplication based on the data in sqlite database

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();
        }

    }


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜