天气预报应用显示错误

时间:2012-05-11 10:10:50

标签: android logcat google-weather-api

我从这个链接获得了天气预报应用程序的示例代码:

http://www.anddev.org/viewtopic.php?t=361

并尝试在模拟器上运行它但显示错误

我尝试了很多东西来解决它,但我不能

如何解决这个问题?

在这一行我得到了错误

xr.parse(new InputSource(url.openStream()));

这些是logcat消息

  05-11 06:39:14.149: E/WeatherForcaster(709): WeatherQueryError
  05-11 06:39:14.149: E/WeatherForcaster(709):   
    org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 190: not well- formed (invalid token)
  05-11 06:39:14.149: E/WeatherForcaster(709): 
    at org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:520)                                            
  05-11 06:39:14.149: E/WeatherForcaster(709):  
   at org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)
      05-11 06:39:14.149: E/WeatherForcaster(709): 
        at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:318)
         05-11 06:39:14.149: E/WeatherForcaster(709):   
          at org.apache.harmony.xml.ExpatReader.parse(ExpatReader.java:275)    
        05-11 06:39:14.149: E/WeatherForcaster(709): 
         at  org.anddev.android.weatherforecast.Weatherforecast$1.onClick(Weatherforecast.java:74)                                                                                  
       05-11 06:39:14.149: E/WeatherForcaster(709):     
             at android.view.View.performClick(View.java:2485)
       05-11 06:39:14.149: E/WeatherForcaster(709): 
            at android.view.View$PerformClick.run(View.java:9080)
         05-11 06:39:14.149: E/WeatherForcaster(709):   
           at android.os.Handler.handleCallback(Handler.java:587)
            05-11 06:39:14.149: E/WeatherForcaster(709):    
             at android.os.Handler.dispatchMessage(Handler.java:92)
            05-11 06:39:14.149: E/WeatherForcaster(709):    
              at android.os.Looper.loop(Looper.java:123)
               05-11 06:39:14.149: E/WeatherForcaster(709): 
                at android.app.ActivityThread.main(ActivityThread.java:3683)    
               05-11 06:39:14.149: E/WeatherForcaster(709):     
                at java.lang.reflect.Method.invokeNative(Native Method)
     05-11 06:39:14.149: E/WeatherForcaster(709):   
               at java.lang.reflect.Method.invoke(Method.java:507)
         05-11 06:39:14.149: E/WeatherForcaster(709):   
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
      05-11 06:39:14.149: E/WeatherForcaster(709):  
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

1 个答案:

答案 0 :(得分:1)

您可能遇到源XML编码问题。 尝试将InputSource的编码设置为UTF8。 这是一个例子:

    InputSource is = new InputSource(url.openStream());
    is.setEncoding("UTF-8");
    xr.parse(is);