2012-05-10 84 views
0

我使用KSOAP在我的應用程序調用一個webservices.In是我得到一些exception.I我用下面的代碼:KSOAP例外的Android

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();  
       SoapObject response=(SoapObject)envelope.getResponse();  ------>getting exceptopn here 
} 

我收到以下錯誤:

W/System.err(994): SoapFault - faultcode: 'soap:Server' faultstring: 'System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.NullReferenceException: Object reference not set to an instance of an object. 

W/System.err(994): --- End of inner exception stack trace ---' faultactor: 'null' detail: [email protected] 
W/System.err(994):  at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:116) 
W/System.err(994):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:137) 
W/System.err(994):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:63) 
W/System.err(994):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100) 
W/System.err(994):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 
W/System.err(994):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459) 
W/System.err(994):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512) 
W/System.err(994):  at android.app.ActivityThread.access$2200(ActivityThread.java:119) 
W/System.err(994):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863) 
W/System.err(994):  at android.os.Handler.dispatchMessage(Handler.java:99) 
W/System.err(994):  at android.os.Looper.loop(Looper.java:123) 
W/System.err(994):  at android.app.ActivityThread.main(ActivityThread.java:4363) 
W/System.err(994):  at java.lang.reflect.Method.invokeNative(Native Method) 
W/System.err(994):  at java.lang.reflect.Method.invoke(Method.java:521) 
W/System.err(994):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860) 
W/System.err(994):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) 
W/System.err(994):  at dalvik.system.NativeStart.main(Native Method) 
I/ActivityManager(60): Displayed activity com.redbus/.SearchRoute: 2501 ms (total 2501 ms) 

任何人都可以請幫我..

+0

如我之前說的請貼,你初始化的代碼行'request' – breceivemail

+0

SoapObject請求=新SoapObject空間(namespace,METHOD_NAME); – subburaj

+0

嗨Richa,我必須使用這個代碼。是否我必須使用Soapobject的情況下。 – subburaj

回答

0

你可以計算出你的問題,在這裏運行的代碼::

  SoapObject request = new SoapObject(NAMESPACE,METHODE_NAME); 
      SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11); 
      request.addProperty("image", param[0]); 
      request.addProperty("desc", param[1]); 
      request.addProperty("venueId", param[2]); 
      request.addProperty("userId", param[3]); 
      envelope.setOutputSoapObject(request); 
      envelope.dotNet = true; 
      HttpTransportSE androidHttpTransport = new HttpTransportSE(
        Data.URL_BASE, 20000); 
      try { 
       androidHttpTransport.call(Data.SOAP_ACTION, envelope); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
       responseXML = null; 
      } 
      SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 
      String responseLocal = resultsRequestSOAP.toString(); 

讓我知道如果你仍然有問題,

+0

是的,我仍然有problem.Showing類轉換exception.SoapObject響應=(SoapObject)envelope.bodyIn; \t String responseLocal = response.toString(); \t System.out.println(「subbu =」+ responseLocal); – subburaj

+0

可能依賴於Web響應類型,請嘗試[this](http://stackoverflow.com/questions/4490505/java-lang-classcastexception-org-ksoap2-serialization-soapprimitive) –