Android How to access the weather webservice, use the Internet to find links are not ah

Source: Internet
Author: User


==================== Problem Description ====================

Do a small test of the weather forecast online to find the link how not, have done under the guidance. Appreciate!!
Use or available links!!!!!!!!!!

Http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx

And

Http://www.webxml.com.cn/webservices/weatherwebservice.asmx

It's not going to work! Follow the online example.

Error:

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 A Ssociated 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)



Code:




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 address
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 = "Beijing";
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 = "Today:" + Date.split ("") [0];
Weathertoday = Weathertoday + "\ n weather:" + date.split ("") [1];
Weathertoday = Weathertoday + "\ n temperature:" + Detail.getproperty (5). ToString ();
Weathertoday = Weathertoday + "\ n Wind:" + detail.getproperty (7). ToString () + "\ n";
System.out.println ("Weathertoday is" + weathertoday);
Toast.maketext (This, Weathertoday, Toast.length_long). Show ();

}
}

Are online looking for, Danale to fire!!


==================== Solution 1====================
Both of these interfaces have been invalidated and cannot be accessed, so you can use a browser to test
==================== Solution 2====================
Did the landlord solve it now? Solving
==================== Solution 3====================
is the network permission open?
==================== Solution 4====================
See if there's any return data.
==================== Solution 5====================
Unable to resolve host ' webservice.webxml.com.cn ': No address associated with hostname

This means that the domain name parsing is not normal, sure network OK?
==================== Solution 6====================
Does this website now apply extensively? Look at their interface document, really feel not how ah, do not do a bit of the level of open platform .... ,

Android How to access the weather webservice, use the Internet to find links are not ah

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.