0

天気情報をフランス語で表示しようとしましたが、できません。このコードはこの baseURL http://www.google.com/ig/api?weather=city,stateで動作しますが、フランス語に変更すると動作せず、例外を作る!!

public class WeatherXMLParsing extends GDActivity{
static final String baseURL="http://www.google.com/ig/api?weather=city,state&hl=fr";    
EditText city,state;
TextView tv1,tv2,tv3,tv4,tv5;
ImageView iv;
String c,s;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setActionBarContentView(R.layout.weather_layout_base);

    tv1=(TextView) findViewById(R.id.weath_info);
    tv2=(TextView) findViewById(R.id.weath_temp_x);
    tv3=(TextView) findViewById(R.id.weath_wind_x);
    tv4=(TextView) findViewById(R.id.weath_humidity_x);
    tv5=(TextView) findViewById(R.id.weath_condition_x);
    iv=(ImageView) findViewById(R.id.weath_img);

    DataBind();
}

public void DataBind() {

    StringBuilder URL=new StringBuilder(baseURL);
    String FullURL=URL.toString();
    try {

        URL Website = new URL(FullURL);
        SAXParserFactory spf=SAXParserFactory.newInstance(); 
        SAXParser sp=spf.newSAXParser();
        XMLReader xr=sp.getXMLReader();
        HandlingXMLStuff doingWork=new HandlingXMLStuff();
        xr.setContentHandler(doingWork);
        xr.parse(new InputSource(Website.openStream()));

        String information=doingWork.getInformation();
        String temp=doingWork.getTempInformation();
        String wind=doingWork.getWindInformation();
        String humudity=doingWork.getHumudityInformation();
        String condition=doingWork.getConditionInformation();

        Log.d("weath_info", information);
        Log.d("weath_info", temp);
        Log.d("weath_temp", wind);
        Log.d("weath_wind", humudity);
        Log.d("weath_humud", condition);

        tv1.setText(information);
        tv2.setText(temp+"°C");
        tv3.setText(wind);
        tv4.setText(humudity);
        tv5.setText(condition);

                    if(condition.equals("Cloudy"))
                    {
                        iv.setImageResource(R.drawable.cloudy);
                    }
                    else if(condition.equals("Partly Cloudy"))
                    {
                        iv.setImageResource(R.drawable.partly_cloudy);
                    }
                    else if(condition.equals("Rainy"))
                    {
                        iv.setImageResource(R.drawable.rainy);
                    }
                    else if(condition.equals("Clear"))
                    {
                        iv.setImageResource(R.drawable.sunny);
                    }
                    else{
                        iv.setImageResource(R.drawable.mostly_sunny);
                    } 
    } catch (Exception e) {
tv1.setText("Erreur internet");
tv2.setVisibility(View.INVISIBLE);
tv3.setVisibility(View.INVISIBLE);


    }
}
}





public class HandlingXMLStuff extends DefaultHandler {
XMLDataCollected info=new XMLDataCollected();
public String getTempInformation(){

    return info.tempToString();
}
public String getConditionInformation(){

    return info.conditionToString();
}
public String getWindInformation(){

    return info.windToString();
}
public String getHumudityInformation(){

    return info.humudityToString();
}
public String getInformation(){

    return info.informationToString();
}

@Override
public void startElement(String uri, String localName, String qName,Attributes attributes) throws SAXException {

    if (localName.equals("city"))
    {
        String city=attributes.getValue("data");    
        info.setCity(city);
    }

    else if (localName.equals("temp_c"))
    {
        String t=attributes.getValue("data");
        int temp=Integer.parseInt(t);
        info.setTemp(temp);
    }

    else if (localName.equals("humidity"))
    {
        String humidity=attributes.getValue("data");
        info.setHumidity(humidity);
    }

    else if (localName.equals("wind_condition"))
    {
        String wind=attributes.getValue("data");
        info.setWind(wind);
    }

    else if (localName.equals("forecast_date"))
    {
        String date=attributes.getValue("data");
        info.setDate(date);
    }
    else if (localName.equals("condition"))
    {
        String condition=attributes.getValue("data");
        info.setCondition(condition);
    }
}



}










public class XMLDataCollected {

String city=null,humidity=null,wind=null,date=null,condition=null;
int temp=0;

public void setCity(String c)
{
    city=c; }
public void setCondition(String cnd)
{
    condition=cnd;  }
public void setTemp(int t)
{
    temp=t; }
public void setHumidity(String h)
{
    humidity=h; }
public void setWind(String w)
{
    wind=w; }
public void setDate(String d)
{
    date=d; }
public String cityToString()
{
    return city;    
}

public String conditionToString()
{
    return condition;   
}
public String informationToString()
{
    return "Weather in "+city+" for "+date; 
}
public String tempToString()
{
    return temp+""; 
}
public String humudityToString()
{
    return humidity;    
}
public String windToString()
{
    return wind;    
}
}

スタック トレースは次のとおりです。

05-23 03:20:04.376: W/System.err(6355): java.net.UnknownHostException: Host is unresolved: www.google.com:80
05-23 03:20:04.386: W/System.err(6355):     at java.net.Socket.connect(Socket.java:1037)
05-23 03:20:04.396: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
05-23 03:20:04.396: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager$ConnectionPool.getHttpConnection(HttpConnectionManager.java:145)
05-23 03:20:04.406: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionManager.getConnection(HttpConnectionManager.java:67)
05-23 03:20:04.406: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getHTTPConnection(HttpURLConnection.java:821)
05-23 03:20:04.416: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:807)
05-23 03:20:04.416: W/System.err(6355):     at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1051)
05-23 03:20:04.416: W/System.err(6355):     at java.net.URL.openStream(URL.java:653)
05-23 03:20:04.436: W/System.err(6355):     at com.pfe.meteo.WeatherXMLParsing.DataBind(WeatherXMLParsing.java:55)
05-23 03:20:04.446: W/System.err(6355):     at com.pfe.meteo.WeatherXMLParsing.onCreate(WeatherXMLParsing.java:40)
05-23 03:20:04.446: W/System.err(6355):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-23 03:20:04.456: W/System.err(6355):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
05-23 03:20:04.456: W/System.err(6355):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
05-23 03:20:04.466: W/System.err(6355):     at android.app.ActivityThread.access$2200(ActivityThread.java:119)
05-23 03:20:04.466: W/System.err(6355):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
05-23 03:20:04.466: W/System.err(6355):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-23 03:20:04.476: W/System.err(6355):     at android.os.Looper.loop(Looper.java:123)
05-23 03:20:04.476: W/System.err(6355):     at android.app.ActivityThread.main(ActivityThread.java:4363)
05-23 03:20:04.488: W/System.err(6355):     at java.lang.reflect.Method.invokeNative(Native Method)
05-23 03:20:04.488: W/System.err(6355):     at java.lang.reflect.Method.invoke(Method.java:521)
05-23 03:20:04.488: W/System.err(6355):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
05-23 03:20:04.496: W/System.err(6355):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
05-23 03:20:04.496: W/System.err(6355):     at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

0

インターネット接続と DNS サーバーを確認してください - 問題があるようです

于 2012-05-23T13:34:20.380 に答える