0

以下のコードは通常は問題なく動作しますが、コードの実行中に突然接続が失われると、エラーが発生することがよくあります。この質問の最後で報告したエラーは、430 行目付近から始まっているようです。

androidHttpTransport.call(soap_action, envelope); 

以下は、私の仕事をする AsyncTask です。

  private class CheckUpdateTask extends AsyncTask<Void, Void, ArrayList<String>>{
            private SoapObject response = null;
            ArrayList<String> methodsResult = new ArrayList<String>();      
    @Override
        protected ArrayList<String> doInBackground(Void... params) {
            // TODO Auto-generated method stub
                SoapObject Request = new SoapObject(NAMESPACE,"CheckUpdate");
                Request.addProperty("Username", username);
                Request.addProperty("Password", password);

            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            envelope.setOutputSoapObject(Request);
            final String soap_action = NAMESPACE+"CheckUpdate";

            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            try {
                androidHttpTransport.call(soap_action, envelope); //line 430, where error occurs!

            } catch (IOException e) {
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                e.printStackTrace();
                            }

            try {
                response = (SoapObject)envelope.getResponse();
                ...here I use the returned data for build my array (methodsResult)

            SoapObject pi = (SoapObject)response.getProperty(0);
            } catch (SoapFault e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }


            return methodsResult; 
    }

    @Override
    protected void onPostExecute(ArrayList<String> result) {
        // TODO Auto-generated method stub
        String[] resultArr= result.toArray(new String[result.size()]);
        new callWS().execute(resultArr);

        super.onPostExecute(result);
    }
  }

そしてここに私のエラーメッセージ:

05-07 12:58:47.920: E/AndroidRuntime(31053): FATAL EXCEPTION: AsyncTask #5
05-07 12:58:47.920: E/AndroidRuntime(31053): java.lang.RuntimeException: An error occured while executing doInBackground()
05-07 12:58:47.920: E/AndroidRuntime(31053):    at android.os.AsyncTask$3.done(AsyncTask.java:278)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.lang.Thread.run(Thread.java:856)
05-07 12:58:47.920: E/AndroidRuntime(31053): Caused by: java.lang.NullPointerException
05-07 12:58:47.920: E/AndroidRuntime(31053):    at org.ksoap2.transport.ServiceConnectionSE.getResponseProperties(ServiceConnectionSE.java:85)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:167)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:96)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at host.framework.ServicePromemoria$CheckUpdateTask.doInBackground(ServicePromemoria.java:430)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at host.framework.ServicePromemoria$CheckUpdateTask.doInBackground(ServicePromemoria.java:1)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
05-07 12:58:47.920: E/AndroidRuntime(31053):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
05-07 12:58:47.920: E/AndroidRuntime(31053):    ... 5 more

問題が接続のリークに関連しているかどうかはわかりません。

4

1 に答える 1

1

どの変数も null に設定されていないことを確認してください。そうでない場合、問題は http 呼び出しであり、単に例外を処理します。

try { 
    androidHttpTransport.call(soap_action, envelope); //line 430, where error occurs!
} catch (IOException e) {
    e.printStackTrace();
} catch (XmlPullParserException e) {
    e.printStackTrace();
} catch (Exception e) {
    enter code here
}

それが役に立てば幸い!

于 2013-05-07T14:00:52.337 に答える