异步后台线程WebServices

时间:2014-05-26 10:10:34

标签: android web-services android-asynctask

我收到一条错误,告诉我在运行时它无法序列化。

异常是在

行捕获错误

androidHttpTransport.call(SOAP_UPDATE,envelope);

错误是:java.lang.RuntimeException:无法序列化:sprint.telematics.sprinttelematicstracking.RequestInfo@42df66d8

我正在使用WebServices并尝试在后台AsyncThread上运行一个但仍然收到错误。 ASyncThread是MainActivity的InnerClass

public class JobStatus extends AsyncTask<SoapObject,Object, SoapObject> 
{
    String sessionID;
    Globals globals;

    int jobStatus = 0, requestsSent = 0;
    Context context;
    CreateJobStatus createJobStatus;
    Bundle extras = getIntent().getExtras();

    @Override
    protected SoapObject doInBackground(SoapObject... request) 
    {
        // TODO Auto-generated method stub

        for(int i=10;i<100;i +=10)
        {
            try
            {
                    requestSent = requestSent + 1;

                    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

                    envelope.setOutputSoapObject(request[0]);
                    envelope.dotNet = true;

                    try
                    {
                        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL_UPDATE);

                        //this is the actual part that will call the web service
                        androidHttpTransport.call(SOAP_UPDATE, envelope);

                        //Get the SoapResult from the envelope body
                        SoapObject result = (SoapObject)envelope.bodyIn;
                        if(result != null)
                        {
                            jobStatus = jobStatus + 1;
                            TextView jobStatus_ = (TextView) findViewById(R.id.JobsStatus);
                            jobStatus_.setText(jobs + " of " + requestsSent);
                        } 
                } 
                catch(Exception ex)
                {

                    ex.printStackTrace();
                }
                }
                publishProgress(i);
            }
            catch(InterruptedException ex)
            {
                ex.printStackTrace();
            }
        }
        return null;
    }
}

1 个答案:

答案 0 :(得分:0)

删除

TextView jobStatus_ = (TextView) findViewById(R.id.JobsStatus);
jobStatus_.setText(jobs + " of " + requestsSent);

来自

  

doInBackground

(您无法从后台线程访问UI元素) 相反,将它们放在AsyncTask的onPostExecute方法上。