【发布时间】:2014-05-26 10:10:34
【问题描述】:
我收到一个错误,告诉我它在运行时无法序列化。
一个异常正在捕获该行的错误
androidHttpTransport.call(SOAP_UPDATE, 信封);
错误是:java.lang.RuntimeException: Cannot serialize: 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;
}
}
【问题讨论】:
-
因为你试图从后台线程访问 UI 元素并且不使用 Thread.sleep() 方法。\
-
我应该摆脱 Thread.sleep() 吗?
标签: android web-services android-asynctask