2011-09-16 6 views
3

ブラックベリーのSOAP検証クラスを完了しましたが、自動サインイン機能を実装する際に問題が発生しています。私のアプリケーションが起動すると、メインクラスがデータベースを読み込み、チックボックス(またはチェックボックス)がチェックされているかどうかを確認し、そうであればSOAP validateUserを実行するコードを実行し、次の画面に進みます。検証は正常に動作し、正しい値がデータベースから取得されますが、Ui.getUiEngine()。pushScreen(新しいContentScreen())を使用しようとすると失敗します。私は現在の画面をポップしようとも役に立たなかった。ここでUi.getUiEngine()。pushScreen(new ContentScreen())problem

私の主な方法とSOAPの検証方法は、まず、メイン、次のとおりです。

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

とSOAPの検証:

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

    } 

、最後に私はエラーかもしれないと思うものを:

[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 [email protected]|[email protected]|-1 

答えて

3

これをバックグラウンドから実行するには、イベントハンドラスレッドで実行するようにコードをスケジュールする必要があります。

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. .. 
} 

これら三つの違いは、それらの動作です:あなたは、次のいずれかを使用することができますinvokeLater

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

1日2回1に。ありがとうございました –

+0

ありがとう:)私は助けることができてうれしい –

2

でこれを行うことができます。 InvokeAndWaitは、スレッド内のUIを呼び出してから作業を続行しますが、InvokeLaterはスレッド内で作業を完了し、UIを呼び出します。

チェックこのこの問題の詳細なヘルプについてlinkと本当にあなたの問題が何であるかを理解する:あなたは素晴らしいしてきた