我试图通过调用需要将类对象作为输入参数的函数来通过我的android应用程序消耗Web服务。但是在拨打电话时出现错误java.lang.RuntimeException:无法序列化:MyClass
我尝试了以下解决方案,但这没有帮助:
KSOAP2 java.lang.RuntimeException: Cannot serialize
https://code.google.com/p/ksoap2-android/issues/detail?id=141
码:
SoapObject request = helperLogin();
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER10);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
envelope.addMapping(NAMESPACE, "L1UserProfileRowDTO", L1UserProfileRowDTO.class);
envelope.addMapping(NAMESPACE, "L1UserRowDTO", L1UserRowDTO.class);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
TextView ACTV = (TextView) findViewById(R.id.textView1);
androidHttpTransport.call(SOAP_ACTION, envelope);
最后一行抛出异常。
我的类实现了可序列化的接口,并且还具有默认的构造函数。
请帮忙。
最佳答案
我能够解决问题:
public class L1UserProfileRowDTO extends Vector<String> implements KvmSerializable
以及以下功能:
@Override
public Object getProperty(int arg0) {
// TODO Auto-generated method stub
return this.get(arg0);
}
@Override
public int getPropertyCount() {
// TODO Auto-generated method stub
return this.size();
}
@Override
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
// TODO Auto-generated method stub
arg2.name = "string";
arg2.type = PropertyInfo.STRING_CLASS;
}
@Override
public void setProperty(int arg0, Object arg1) {
// TODO Auto-generated method stub
this.add(arg1.toString());
}