1

好的,这是我的问题:

我正在发送一个肥皂请求,我得到了一个有效的答案,一切正常,我在 responsedump 中得到了有效的输出。但调用 evelope.getResponse() 在:

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);        
//adding parameters
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.setAddAdornments(false);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.debug = true;
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject so = (SoapObject) envelope.getResponse();

抛出此异常:

Caused by: java.lang.NullPointerException
at org.ksoap2.serialization.SoapSerializationEnvelope.getResponse(SoapSerializationEnvelope.java:521)

错误位于 ksoap2 源的 getResponse 中:

/** * 来自soap调用的响应。从包装对象中拉出对象并将其返回。* * @since 2.0.3 * @return 来自soap调用的响应。* @throws SoapFault */

public Object getResponse() throws SoapFault {
    if (bodyIn instanceof SoapFault) {
        throw (SoapFault) bodyIn;
    }
    KvmSerializable ks = (KvmSerializable) bodyIn; <-- Line 521

if (ks.getPropertyCount()==0) {
    return null;
} else if(ks.getPropertyCount()==1) {
    return ks.getProperty(0);
} else {
    Vector ret = new Vector();
    for(int i=0;i<ks.getPropertyCount();i++){
        ret.add(ks.getProperty(i));
    }
    return ret;
}

}

4

1 回答 1

1

试试这个而不是 SoapObject

 SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
于 2012-07-11T08:17:06.197 回答