2016-05-12 58 views
-1

這是我的第一篇文章,關於堆棧溢出, 嗯這是我的問題我是一個開墾機器人,我不得不使用KSOAP2從Web服務獲取數據。所以我覺得這個網絡服務: http://www.w3schools.com/xml/tempconvert.asmxksoap2 android打電話,得到null異常

而我試圖得到的結果只有一個TextView電視; 因此,這裏是我的代碼

final static String SOAP_ACTION = "http://www.w3schools.com/xml/CelsiusToFahrenheit"; 
final static String METHOD = "CelsiusToFahrenheit"; 
final static String URL = "http://www.w3schools.com/xml/tempconvert.asmx"; 
final static String NAME_SPACE = "http://www.w3schools.com/xml/"; 

TextView tv; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_fram_rest); 

    tv = (TextView) findViewById(R.id.myTv); 


    SoapObject request = new SoapObject(NAME_SPACE, METHOD); 


    request.addProperty("Celsius", "32"); 


    SoapSerializationEnvelope soapE = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    soapE.dotNet = true; 
    soapE.setOutputSoapObject(request); 

    HttpTransportSE AHT = new HttpTransportSE(URL); 
    try { 
     AHT.call(SOAP_ACTION, soapE); 
     tv.setText("done"); 
/*  SoapPrimitive resultString = (SoapPrimitive) soapSerializationEnvelope.getResponse(); 
     tv.setText("statut: " + resultString.toString());*/ 
    } catch (Exception e) { 
     String str = e.getMessage(); 
     tv.setText("statut error: " + str); 
    } 
} 

我使用的Internet的權限,但我得到的異常呼叫(SOAP_ACTION,...)和「Statut錯誤:空」在我的電視

感謝您的幫助!

P.S:我正在使用android studio 2.0!

+0

看到我的回答如下。 – 2016-05-12 11:37:20

回答

0

取而代之的是

HttpTransportSE AHT = new HttpTransportSE(URL); 
    try { 
     AHT.call(SOAP_ACTION, soapE); 
     tv.setText("done"); 
/*  SoapPrimitive resultString = (SoapPrimitive) soapSerializationEnvelope.getResponse(); 
     tv.setText("statut: " + resultString.toString());*/ 
    } catch (Exception e) { 
     String str = e.getMessage(); 
     tv.setText("statut error: " + str); 
    } 

使用這樣的:

HttpTransportSE AHT = new HttpTransportSE(URL); 
try{ 
    AHT,call(SOAP_ACTION, soapE); 
SoapPrimitive response = (SoapPrimitive)soapE.getResponse(); 

tv.setText(Interger.parseInt(response.toString())); 

}catch(Exception e){ 
String msg = e.getMessage();  

} 
+0

不是邏輯bro,這是正常的,因爲錯誤從這裏開始,我會得到相同的異常:AHT.call(SOAP_ACTION,soapE);仍然無效 –