0

BlackBerryアプリに「待機画面」を実装しようとしています。ユーザーが「ログイン」をクリックすると画面が表示され、ログインが正常に完了すると画面が消えます。「ログイン」リスナーで画面を呼び出した後、methdを呼び出してWebサービスからデータをフェッチします。データを取得して新しい画面が表示されると、「待機画面」が消えるはずです。ただし、ログインをクリックするUncaught - RuntimeExceptionと、新しい画面が表示され、その上に「待機画面」が表示されます。誰かがこれを手伝ってくれますか?

public class MessageScreen extends PopupScreen
{
    private String message;

    public MessageScreen (String message)
    {
        super( new HorizontalFieldManager(), Field.NON_FOCUSABLE);
        this.message = message;
        final BitmapField logo = new BitmapField(Bitmap.getBitmapResource( "cycle.gif"));
        logo.setSpace( 5, 5 );
        add(logo);

        RichTextField rtf = new RichTextField(message, Field.FIELD_VCENTER | Field.NON_FOCUSABLE | Field.FIELD_HCENTER);
        rtf.setEditable( false );

        add(rtf);
    }
}

私はこれを「ログイン」クリックイベント-ボタンリスナーで呼んでいます。

public void fieldChanged(Field field, int context)
{
    // Push appropriate screen depending on which button was clicked
    String uname = username.getText();
    String pwd = passwd.getText();
    if (uname.length() == 0 || pwd.length()==0) {
        Dialog.alert("One of the textfield is empty!");
    } else {
        C0NNECTION_EXTENSION=checkInternetConnection();
        if(C0NNECTION_EXTENSION==null)
        {
            Dialog.alert("Check internet connection and try again");
        }
        else
        {
            UiApplication.getUiApplication().invokeLater( new Runnable()
            {
                public void run ()
                {
                    UiApplication.getUiApplication().pushScreen( new MessageScreen("Signing in...") );
                }
            } );
            doLogin(uname, pwd);
        }
    }
}

private String doLogin(String user_id, String password)
{
    String URL ="";
    String METHOD_NAME = "ValidateCredentials";
    String NAMESPACE = "http://tempuri.org/";
    String SOAP_ACTION = NAMESPACE+METHOD_NAME;
    SoapObject resultRequestSOAP = null;
    HttpConnection httpConn = null;
    HttpTransport httpt;
    SoapPrimitive response = null;
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    request.addProperty("username", user_id);
    request.addProperty("password", password);
    System.out.println("The request is=======" + request.toString());
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    httpt = new HttpTransport(URL+C0NNECTION_EXTENSION);
    httpt.debug = true;
    try
    {
        httpt.call(SOAP_ACTION, envelope);
        response = (SoapPrimitive) envelope.getResponse();
        String result =  response.toString();
        resultRequestSOAP = (SoapObject) envelope.bodyIn;
        String[] listResult = split(result, sep);
        strResult = listResult[0].toString();
        strsessionFirstName = listResult[1].toString();
        strsessionLastName = listResult[2].toString();
        strsessionPictureUrl = MAINURL + listResult[3].substring(2);
        strsessionStatusId = listResult[4].toString();
        strsessionStatusMessage = listResult[5].toString();
        strsessionLastUpdateTst = listResult[6].toString();

        if(strResult.equals("credentialaccepted"))
        {
            if(checkBox1.getChecked() == true)
            {
                persistentHashtable.put("username", user_id);
                persistentHashtable.put("password", password);
            }
            Bitmap bitmap = getLiveImage(strsessionPictureUrl, 140, 140);
            StatusActivity nextScreen = new StatusActivity();
            nextScreen.getUsername(user_id);
            nextScreen.getPassword(password);
            nextScreen.setPictureUrl(bitmap);
            nextScreen.setImage(strsessionPictureUrl);
            nextScreen.setFirstName(strsessionFirstName, strsessionLastName, strsessionLastUpdateTst, strsessionStatusMessage);
            UiApplication.getUiApplication().pushScreen(nextScreen);
            UiApplication.getUiApplication().invokeLater( new Runnable()
            {
                public void run ()
                {
                    UiApplication.getUiApplication().pushScreen( UiApplication.getUiApplication().getActiveScreen() );
                }
            } );
        }
        if(strResult.equals("credentialdenied"))
        {
            Dialog.alert("Invalid login details.");
            UiApplication.getUiApplication().pushScreen(new LoginTestScreen() );
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        System.out.println("The exception is IO==" + e.getMessage());
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        System.out.println("The exception xml parser example==="
        + e.getMessage());
    }

    System.out.println( resultRequestSOAP);
    //UiApplication.getUiApplication().pushScreen( UiApplication.getUiApplication().getActiveScreen() );
    return response + "";

    //UiApplication.getUiApplication().pushScreen(new InfoScreen());
    //Open a new Screen
} 
4

3 に答える 3

2

これまでのところ、問題は 1 つだけです。UI スレッドでのネットワークです。すべてのネットワーク操作を別の に入れてくださいThread.run()

次の方法でも、より詳細なエラーの説明を得ることができます。

于 2012-08-09T08:55:32.453 に答える