====================問題描述==================== 作個天氣預報的小測試用網上找的連接怎麼不行,有作過的指導下。感激涕零!! 求用法或可用連接!!!!!!!!!! http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx 和 http://www.webxml.com.cn/webservices/weatherwebservice.asmx 都是不行的!跟着網上例子作的。 錯誤: 11-13 19:27:10.545: W/System.err(29917): java.net.UnknownHostException: Unable to resolve host "webservice.webxml.com.cn": No address associated with hostname 11-13 19:27:10.545: W/System.err(29917): at java.net.InetAddress.lookupHostByName(InetAddress.java:426) 11-13 19:27:10.545: W/System.err(29917): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242) 11-13 19:27:10.545: W/System.err(29917): at java.net.InetAddress.getAllByName(InetAddress.java:220) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpConnection.connect(HttpConnection.java:128) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:282) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 11-13 19:27:10.545: W/System.err(29917): at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:80) 11-13 19:27:10.545: W/System.err(29917): at org.ksoap2.transport.ServiceConnectionSE.connect(ServiceConnectionSE.java:46) 11-13 19:27:10.545: W/System.err(29917): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:68) 11-13 19:27:10.550: W/System.err(29917): at com.testtv.core.WeatherActivity.getWeather(WeatherActivity.java:102) 11-13 19:27:10.550: W/System.err(29917): at com.testtv.core.WeatherActivity$2$1.run(WeatherActivity.java:76) 11-13 19:27:10.550: W/System.err(29917): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 11-13 19:27:10.550: W/System.err(29917): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 11-13 19:27:10.550: W/System.err(29917): at java.lang.Thread.run(Thread.java:856) 11-13 19:27:10.550: W/System.err(29917): Caused by: libcore.io.GaiException: getaddrinfo failed: EAI_NODATA (No address associated with hostname) 11-13 19:27:10.550: W/System.err(29917): at libcore.io.Posix.getaddrinfo(Native Method) 11-13 19:27:10.550: W/System.err(29917): at libcore.io.ForwardingOs.getaddrinfo(ForwardingOs.java:55) 11-13 19:27:10.550: W/System.err(29917): at java.net.InetAddress.lookupHostByName(InetAddress.java:411) 代碼: package com.testtv.core; import java.io.UnsupportedEncodingException; import java.util.concurrent.Executor; import java.util.concurrent.Executors; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.Toast; public class WeatherActivity extends Activity { /** Called when the activity is first created. */ private Button okButton; /** Called when the activity is first created. */ private static final String NAMESPACE = "http://WebXml.com.cn/"; // WebService地址 private static String URL = "http://www.webxml.com.cn/webservices/weatherwebservice.asmx"; private static final String METHOD_NAME = "getWeatherbyCityName"; private static String SOAP_ACTION = "http://WebXml.com.cn/getWeatherbyCityName"; private String weatherToday; private SoapObject detail; private Handler webHandler; private final static String TAG = "WeatherActivity"; private final static int SHOW_WEATHER=10; private Executor webExcutor; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.weather); this.webHandler=new Handler() { @Override public void handleMessage(Message msg) { // TODO Auto-generated method stub if(msg.what==SHOW_WEATHER) { try { parseWeather(detail); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }; okButton = (Button) this.findViewById(R.id.btn_Search); okButton.setOnClickListener(new Button.OnClickListener() { public void onClick(View v) { final String city = "北京"; if(webExcutor==null) { webExcutor=Executors.newFixedThreadPool(1); } webExcutor.execute(new Runnable() { public void run() { // TODO Auto-generated method stub getWeather(city); } }); } }); } public void getWeather(String cityName) { try { System.out.println("rpc------"); SoapObject rpc = new SoapObject(NAMESPACE, METHOD_NAME); System.out.println("rpc" + rpc); System.out.println("cityName is " + cityName); rpc.addProperty("theCityName", cityName); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.bodyOut = rpc; envelope.dotNet = true; envelope.setOutputSoapObject(rpc); HttpTransportSE ht = new HttpTransportSE(URL); // AndroidHttpTransport ht = new AndroidHttpTransport(URL); ht.debug = true; ht.call(SOAP_ACTION, envelope); // ht.call(null, envelope); // SoapObject result = (SoapObject)envelope.bodyIn; // detail = (SoapObject) // result.getProperty("getWeatherbyCityNameResult"); detail = (SoapObject) envelope.getResponse(); Log.d(TAG, detail.toString()); Message msg = new Message(); msg.what=SHOW_WEATHER; webHandler.sendMessage(msg); // Toast.makeText(this, detail.toString(), Toast.LENGTH_LONG).show(); return; } catch (Exception e) { e.printStackTrace(); } } private void parseWeather(SoapObject detail) throws UnsupportedEncodingException { String date = detail.getProperty(6).toString(); weatherToday = "今天:" + date.split("")[0]; weatherToday = weatherToday + "\n天氣:" + date.split("")[1]; weatherToday = weatherToday + "\n氣溫:" + detail.getProperty(5).toString(); weatherToday = weatherToday + "\n風力:" + detail.getProperty(7).toString() + "\n"; System.out.println("weatherToday is " + weatherToday); Toast.makeText(this, weatherToday, Toast.LENGTH_LONG).show(); } } 都是網上找的,大拿們速來救火!! ====================解決方案1==================== 這兩個接口都已經失效了,無法訪問,你找個能用的,用瀏覽器就能夠測試 ====================解決方案2==================== 樓主如今解決了嗎?求解 ====================解決方案3==================== 網絡權限開了嗎 ====================解決方案4==================== 看看有沒有返回數據就清楚了 ====================解決方案5==================== Unable to resolve host "webservice.webxml.com.cn": No address associated with hostname 這個意思是域名解析不正常,確信網絡OK? ====================解決方案6==================== 這個網站如今應用普遍嗎? 看了一下他們的接口文檔,真心以爲不怎麼樣啊,沒有一點作開放平臺的水準。。。。,