0

我正在使用以下代码:

   SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
   SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
   envelope.setOutputSoapObject(request);
   envelope.dotNet=true;            
   HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);  
   try
   {
        androidHttpTransport.call(SOAP_ACTION, envelope);              
        SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
        Log.i("myApp", response.toString());  
        TextView tv = new TextView(this);
        tv.setText("message="+response.toString());
        setContentView(tv);                              
    } catch (Exception e) {
        e.printStackTrace();
    }

它显示以下错误:

I/Process(3977): Sending signal. PID: 3977 SIG: 9
 W/System.err(4059): java.lang.ClassCastException: org.ksoap2.serialization.SoapObject     
 W/System.err(4059):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
 W/System.err(4059):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
 W/System.err(4059):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
 W/System.err(4059):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
 W/System.err(4059):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
 W/System.err(4059):    at android.os.Handler.dispatchMessage(Handler.java:99)
 W/System.err(4059):    at android.os.Looper.loop(Looper.java:123)
 W/System.err(4059):    at android.app.ActivityThread.main(ActivityThread.java:4627)
 W/System.err(4059):    at java.lang.reflect.Method.invokeNative(Native Method)
 W/System.err(4059):    at java.lang.reflect.Method.invoke(Method.java:521)
 W/System.err(4059):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
 W/System.err(4059):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
 W/System.err(4059):    at dalvik.system.NativeStart.main(Native Method)
4

1 回答 1

0

尝试

SoapObject response = (SoapObject)envelope.getResponse();

代替

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
于 2012-05-09T13:35:21.070 回答