2 ssummeraw ssummeraw 于 2013.08.07 16:11 提问

使用AsyncTask调用web服务器

如果代码正在执行,连接突然中断,错误就会发生 ,错误好像就发生在line 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);
    }
  }

错误信息:

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

我不确定这个问题是否与断开连接有关。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!