KSOAP空指针异常

时间:2012-05-16 11:05:41

标签: android ksoap2

  

可能重复:
  Cannot serialize issue in KSOAP in android

在我的应用程序中,我正在使用SOAP服务,因为我的SOAP请求结构是

<authentication>
        <LoginID>string</LoginID>
        <Password>string</Password>
      </authentication>
      <ID>int</ID>
      <ID>int</ID>
      <dojStr>string</dojStr>
      <Data>
        <Keys>
          <POfStringString>
            <V>string</V>
            <K>string</K>
          </POfStringString>
          <POfStringString>
            <V>string</V>
            <K>string</K>
          </POfStringString>
        </Keys>
        <CriteriaKeys>
          <POfStringString>
            <V>string</V>
            <K>string</K>
          </POfStringString>
          <POfStringString>
            <V>string</V>
            <K>string</K>
          </POfStringString>
        </CriteriaKeys>
        <No>int</No>
        <Size>int</Size>
      </Data>    
  </soap:Body>
</soap:Envelope>

我的代码如下:

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);           
            SoapObject authentication = new SoapObject(NAMESPACE,"authentication"); 
            SoapObject pagination = new SoapObject(NAMESPACE,"pagination"); 

                 authentication.addProperty(usrid); 
                 authentication.addProperty(pass);  

            request.addSoapObject(authentication); 

                request.addProperty(Id);   
                request.addProperty(Id);  
                request.addProperty(dte);

                PropertyInfo page =new PropertyInfo();    
                page.setName("V");  
//          page.setName("K");   
            page.setValue("10");
            page.setType(String.class);
            pagination.addProperty(page);

                request.addSoapObject(pagination);


                request.addProperty(no);
                request.addProperty(size);    

              SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
//          envelope.addMapping(NAMESPACE, "authentication", new Array().getClass());
            envelope.dotNet=true;           
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);    
            try
            {         
                androidHttpTransport.call(SOAP_ACTION,envelope);               
//              SoapPrimitive response = (SoapPrimitive)envelope.getResponse();            
                Object result=(Object)envelope.getResponse(); ----->Getting error here.

我得到的错误是:

    java.lang.NullPointerException
at java.io.Writer.write(Writer.java:152)
at org.kxml2.io.KXmlSerializer.startTag(KXmlSerializer.java:407)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:660)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:645)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:642)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:702)
at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:618)


at org.ksoap2.SoapEnvelope.write(SoapEnvelope.java:198)
    at org.ksoap2.transport.Transport.createRequestData(Transport.java:111)
    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:119)
    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
    at com.redbus.SearchRoute.onCreate(SearchRoute.java:151)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
    at android.app.ActivityThread.access$2200(ActivityThread.java:119)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:4363)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:521)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
    at dalvik.system.NativeStart.main(Native Method)

我是正确设置输入还是我做错了什么。提前谢谢。

1 个答案:

答案 0 :(得分:0)

使用SoapPrimitive result =(SoapPrimitive)envelope.getResponse();和result.toString()

这会奏效。如果这不起作用,我会再给你一个方法