2012-05-19 28 views
0

序列化KSOAP問題,我在我的應用程序中使用SOAP服務,當我打電話SOAP服務它拋出一些不能序列化問題:不能在Android的

 SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);   
    SoapObject authentication = new SoapObject(NAMESPACE,"authentication"); 
    PropertyInfo usrid =new PropertyInfo(); 
    usrid.setName("LoginID"); 
    usrid.setValue("sting"); 
    usrid.setType(String.class); 
    authentication.addProperty(usrid);   

    PropertyInfo pass =new PropertyInfo(); 
    pass.setName("Password"); 
    pass.setValue("string"); 
    pass.setType(String.class); 
    authentication.addProperty(pass); 

    request.addSoapObject(authentication); 

    PropertyInfo nos =new PropertyInfo(); 
    no.setName("No"); 
    no.setValue(no); 
    no.setType(String.class); 
    //authentication.addProperty(no); 
    request.addProperty("Str", nos); 

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request); 
    envelope.dotNet=true;  
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    try 
    { 
      androidHttpTransport.call(SOAP_ACTION,envelope); 
      Object result=(Object)envelope.getResponse(); --------->Here i am getting nullpointer. 
      Log.i("myApp",result.toString());   
      System.out.println("subbu="+result.toString()); 
    } 

我的請求結構是:

<authentication> 
    <LoginID>string</LoginID> 
    <Password>string</Password> 
</authentication> 
<No>string</No> 

我收到錯誤消息:

java.lang.RuntimeException: Cannot serialize:No: 

回答

0

在我看來你的代碼不應該作爲編譯你寫:

PropertyInfo nos =new PropertyInfo(); 
no.setName("No"); 
no.setValue(no); 
no.setType(String.class); 
//authentication.addProperty(no); 
request.addProperty("Str", nos); 

如果你清楚的意思是:

PropertyInfo nos =new PropertyInfo(); 
nos.setName("No"); 
nos.setValue(no); 
nos.setType(String.class); 
//authentication.addProperty(nos); 
request.addProperty("Str", nos); 

無論如何,我覺得這是一個錯字,並在你真正的代碼,你沒有做這個錯誤。
所以要回答你的問題,你應該告訴哪一個是空對象。無法從您提供的代碼片段中猜出它。
使用斷點並在調試模式下運行您的應用程序。然後提供有關空對象的信息。
另外,顯示你的WSDL會有很大的幫助。

+0

Hi andreapier ...實際上,no是一個字符串String no = getIntent()。getStringExtra(「no」);我從previos屏幕獲得。 – subburaj

+0

看一個代碼...你正在用我的答案中指出的PropertyInfo no = new PropertyInfo()覆蓋字符串no。 – andreapier

+0

oh andreapier..sory現在我編輯了代碼..現在我解決了序列化問題,現在我收到錯誤SoapFault - faultcode:'soap:Server'faultstring:'System.Web.Services.Protocols.SoapException:Server was無法處理請求。 ---> System.NullReferenceException:未將對象引用設置爲對象的實例。 – subburaj