java.lang.ClassCastException: org.ksoap2.SoapFault 无法转换为 org.ksoap2.serialization.SoapObject

java.lang.ClassCastException: org.ksoap2.SoapFault cannot be cast to org.ksoap2.serialization.SoapObject

SoapObject request = new SoapObject(NAMESPACE, "api_vps_get_service");
// Property which holds input parameters
PropertyInfo unamePI = new PropertyInfo();

// Set token
unamePI.setName("token");
// Set Value
unamePI.setValue(token);
// Set dataType
unamePI.setType(String.class);
// Add the property to request object
request.addProperty(unamePI);

// Create envelope
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
 envelope.dotNet=true;
 envelope.setOutputSoapObject(request);
// Set output SOAP object
envelope.setOutputSoapObject(request);
// Create HTTP call object
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

try {

    // Invoke web service
    androidHttpTransport.call(SOAP_ACTION+"api_vps_get_service", envelope);
    // Get the response

    SoapObject response=(SoapObject)envelope.bodyIn;


    String reponses = response.toString();
    Log.i("reponse", String.valueOf(reponses));

} catch (Exception e) {
    //Assign Error Status true in static variable 'errored'
    Home.errored = true;
    e.printStackTrace();
}

我收到此错误 java.lang.ClassCastException:org.ksoap2.SoapFault 无法转换为 org.ksoap2.serialization.SoapObject 我尝试了 SoapPrimitive response = (SoapPrimitive) envelope.getResponse();还有 Object response = (Object) envelope.getResponse();但没有成功任何人请告诉我为什么我会出错?

服务器返回错误。所以没有 SoapObject 和 SoapPrimitive。你必须先检查 SoapFoult 是这样的:

if (envelope.bodyIn instanceof SoapFault)
{
    final SoapFault sf = (SoapFault) envelope.bodyIn;
    ... // Stuff
}

此处对此进行了描述: https://code.google.com/p/ksoap2-android/issues/detail?id=177