1

我试图通过调用一个期望类对象作为输入参数的函数来通过我的 android 应用程序使用 Web 服务。但是在拨打电话时出现错误 java.lang.RuntimeException: Cannot serialize: MyClass

我尝试了以下解决方案,但这没有帮助: KSOAP2 java.lang.RuntimeException:无法序列化

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);

最后一行抛出异常。

我的类实现了可序列化的接口,并且还有一个默认的构造函数。请帮忙。

4

2 回答 2

4

我能够解决问题:

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());
}
于 2013-06-20T09:46:28.260 回答
0

You can try implementing Serializable in MyClass. It goes like this -

class MyClass implements Serializable {
   // Constructor

   // Properties

   // Methods
}
于 2013-06-17T13:31:32.613 回答