开发者

Ui.getUiEngine().pushScreen(new ContentScreen()) problem

开发者 https://www.devze.com 2023-04-05 14:27 出处:网络
I have completed a SOAP verification class for my blackberry, however I am having a problem implementing a sign in automatically function. When my application starts the main class reads the database

I have completed a SOAP verification class for my blackberry, however I am having a problem implementing a sign in automatically function. When my application starts the main class reads the database to see if my tickbox (or checkbox) is checked, and if so run the code that does the SOAP validateUser, and then it will go to the next screen. The validation works fine, and the right values are retrieved from the database, but when I try to use the Ui.getUiEngine().pushScreen(new ContentScreen()) it fails. I have tried popping the current screen also to no avail.

Here is my main method and SOAP validation method, first the main:

public HelloBlackBerryScreen() {
        super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
        setTitle("IDL Voucher Application");
        //createDB();
        getValues();
        if(tickBoxes[0]){
            setUserPass();
        }
        if(tickBoxes[1]){
            setUserPass();

        }


        checkBox1 = new CheckboxField("Save Password", tickBoxes[0]);
        checkBox2 = new CheckboxField("Login Automatically",tickBoxes[1]);
        hfm = new HorizontalFieldManager();

        username = new BasicEditField("Username:", usernameField, 100,
                BasicEditField.EDITABLE);
        password = new PasswordEditField("Password: ", passwordBox);
        username.setMargin(20, 10, 20, 20);

        password.setMargin(20, 10, 20, 20);

        this.add(username);
        this.add(new SeparatorField());

        this.add(password);
        this.add(new SeparatorField());


        this.add(checkBox1);
        this.add(new SeparatorField());
        this.add(checkBox2);
        this.add(new SeparatorField());
        this.add(hfm);
        ButtonField buttonField_1 = new ButtonField("Login",
                ButtonField.CONSUME_CLICK | ButtonField.FIELD_LEFT);
        ButtonField buttonField_2 = new ButtonField("SignUp",
                ButtonField.CONSUME_CLICK | ButtonField.FIELD_HCENTER);
        ButtonField buttonField_3 = new ButtonField("Exit",
                ButtonField.CONSUME_CLICK | ButtonField.FIELD_RIGHT);
        // add( buttonField_2 );
        buttonField_1.setMargin(20, 10, 10, 35);
        buttonField_2.setMargin(20, 10, 10, 10);
        buttonField_3.setMargin(20, 10, 10, 10);

        hfm.add(buttonField_1);
        hfm.add(buttonField_2);
        hfm.add(buttonField_3);

        buttonField_1.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field arg0, int arg1) {

                if(username.getText().length() >1 && password.getText().length() >1){
                try {

                    soap();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (XmlPullParserException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                } catch (DatabaseIOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }

            else{
                Dialog.inform("Please enter a username and password");
            }
        }});
        buttonField_2.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field arg0, int arg1) {
                try {
                    signup();
                } catch (DatabaseIOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        });
        buttonField_3.setChangeListener(new FieldChang开发者_运维技巧eListener() {
            public void fieldChanged(Field arg0, int arg1) {
                onClose();

            }
        });


        checkBox1.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field arg0, int arg1) {
                //your code

                if(checkBox1.getChecked() == true){
                    tickBoxes[0] = true;

                    updateFields();
                }
                else{
                    tickBoxes[0] = false;
                    updateFields();
                }

            }
        });
        checkBox2.setChangeListener(new FieldChangeListener() {
            public void fieldChanged(Field arg0, int arg1) {
                //your code

                if(checkBox2.getChecked() == true){
                    tickBoxes[1] = true;

                    //Dialog.inform("Been Checked");
                    updateFields();
                }
                else{
                    tickBoxes[1] = false;
                    //Dialog.inform("Unchecked");
                    updateFields();
                }

            }
        });
        if(tickBoxes[1]){
            try {
                soap();
            } catch (DatabaseIOException e) {
                // TODO Auto-generated catch block
                System.out.println(e.getMessage() + "database problem");
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println(e.getMessage() + "I/O problem");
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                // TODO Auto-generated catch block
                System.out.println(e.getMessage() + "XML problem");
                e.printStackTrace();
            }
        }
    }

and the SOAP validation:

public void soap() throws IOException, XmlPullParserException, DatabaseIOException {
        System.out.println("STARTING");

        if (DeviceInfo.isSimulator()) {
            URL = URL + ";deviceSide=true";
        }
        // start here
        SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME);
        rpc.addProperty("User", username.getText());
        rpc.addProperty("Password", password.getText());
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER11);

        envelope.bodyOut = rpc;
        envelope.dotNet = true;
        envelope.encodingStyle = SoapSerializationEnvelope.XSD;

        HttpTransport ht = new HttpTransport(URL);
        ht.debug = true;

        try {
            ht.call(SOAP_ACTION, envelope);
            System.out.println("IN TRY");
            SoapObject resultProperties = (SoapObject) envelope
                    .getResponse();
            verifyNum = Integer.parseInt(resultProperties.getProperty(0)
                    .toString());
            System.out.println("PARSED INT RIGHT HERE " + verifyNum);
            URLis = resultProperties.getProperty(2).toString();
            System.out.println("URL PARSE HERE " + URL);
        } catch (org.xmlpull.v1.XmlPullParserException ex2) {

        } catch (Exception ex) {

            String bah = ex.toString();

        }
        String oldUser = "";
        try {
            URI uri = URI.create("file:///SDCard/Databases/" + "database1.db");
            sqliteDB = DatabaseFactory.open(uri);
            Statement st = null;
            st = sqliteDB.createStatement("SELECT Name, URL FROM People");
            st.prepare();
            Cursor c = st.getCursor();
            Row r;
            int i = 0;
            while(c.next()) 
            {
                r = c.getRow();
                i++;
                System.out.println(r.getString(0) + "HERE IS NAME");
                System.out.println(r.getString(1) + "HERE IS URL");
               // URLis = r.getString(1);

                oldUser = r.getString(0);

            }

            st.close();
            sqliteDB.close();
        }

        catch ( Exception e ) {
            System.out.println( e.getMessage() + "wut");
            e.printStackTrace();
        }
        if (verifyNum >= 1) {
            try
            {
             URI myURI = URI.create("file:///SDCard/Databases/" + "database1.db"); 
             sqliteDB = DatabaseFactory.open(myURI);
             Statement st = null; 


             st = sqliteDB.createStatement("UPDATE People SET Password='"+ password.getText() + "', Name='" + username.getText() + "', URL='"+URLis +  "' " +
                     "WHERE Name=" + "'"+ oldUser +"'" + "");

             st.prepare();
             st.execute();
             st.close();
             sqliteDB.close();
             System.out.println("base for names is");

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

            Ui.getUiEngine().pushScreen(new ContentScreen());


        } else {
            Dialog.inform("Incorrect Username or Password ");
        }

    }

and at last what I think might be the error:

[0.0] net_rim_cldc-15(4C48DD41)
[0.0]  UiEngineImpl
[0.0]  addScreen
[0.0]  0x81EA
[0.0] net_rim_cldc-15(4C48DD41)
[0.0]  UiEngineImpl$UiEngineOldInterfaceAdapter
[0.0]  pushScreen
[0.0]  0xAF48
[0.0] net_rim_cldc-12(4C48DD41)
 [0.0]  UiApplication
[0.0]  pushScreen
[0.0]  0xBEF4
[0.0] thenewBlackB(4E73609F)
[0.0]  MyApp
[0.0]  <init>
[0.0]  0x3031
[0.0] thenewBlackB(4E73609F)
[0.0]  MyApp
[0.0]  main
[0.0]  0x2FFD
[0.0] Warning: VerticalFieldManager INCREMENTAL_LAYOUT style specified without    specifying USE_ALL_WIDTH | [0.0] USE_ALL_HEIGHT | VERTICAL_SCROLL
[0.0] Warning: VerticalFieldManager INCREMENTAL_LAYOUT style specified without specifying USE_ALL_WIDTH | [0.0] USE_ALL_HEIGHT | VERTICAL_SCROLL
[0.0] FocusHistory: Focus lost; App thenewBlackB; Component net.rim.device.api.ui.component.ButtonField
[0.0] TID:unable to execute in the app mypackage.MyApp@f8f01efd|java.lang.Object@7e392341|-1


To do this from the background you need to schedule your code to run in the event handler thread. You can do this with invokeLater

UiApplication.getUiApplication().invokeLater (new Runnable() 
{
     public void run()
     {
          // push your screen here
     }
}); 


You can use one of the following:

UiApplication.getUiApplication().invokeAndWait ( new Runnable() { public void run {
    //your UI Code here (including push screen, adding new fields, etc. ..
}});

UiApplication.getUiApplication().invokeLater( new Runnable() { public void run {
    //your UI Code here (including push screen, adding new fields, etc. ..
}});

synchronized(UiApplication.getEventLock()) {
    //your UI Code here (including push screen, adding new fields, etc. ..
}

The difference between these three is the behaviour of them. As you can see by their name, InvokeAndWait will invoke the UI in the thread and then continue the work while InvokeLater will finish the work in the thread and then invoke the UI.

Check this link for more help on this problem and to really understand what your problem is:

0

精彩评论

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