简体   繁体   中英

Class Cast exception in SOAP

I am using the following code:

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

It shows the following error:

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)

Try

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

instead of

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM