【问题标题】:can't load open weather map icons无法加载打开的天气地图图标
【发布时间】:2013-09-20 09:14:55
【问题描述】:

我正在使用这个http://www.survivingwithandroid.com/2013/05/build-weather-app-json-http-android.html 教程来了解如何在我的应用程序中使用天气服务。我运行本教程,它工作正常。但我有一个问题。无法加载图标。 Logcat 错误是

java.io.FileNotFoundExeption: http://openweathermap.org/img/w/ at libcore.net.http.HttpURLConnectionTmpl.getInputStream(HttpURLConnctionTmpl.java:186) 

当我在 Chrome 中打开此链接时,我可以看到图像,所以我不知道为什么找不到它。 代码在那里https://github.com/survivingwithandroid/Surviving-with-android/tree/master/WeatherApp 文件“WeatherHttpClient.java”第 87 行出错

【问题讨论】:

    标签: android


    【解决方案1】:

    您正在尝试将目录加载为文件流。不知道为什么这会导致 FileNotFoundException 但值得尝试使用 URL:http://openweathermap.org/img/w/<one-of-the-files>.png

    至少文件应该可以打开。

    【讨论】:

      【解决方案2】:

      添加 .png 文件扩展名

      例子

      con = (HttpURLConnection) (new URL(IMG_URL + code +".png")).openConnection();

      【讨论】:

        【解决方案3】:

        面对同样的问题,只需像下面这样更改您的 url 并正常工作 https://openweathermap.org/img/wn/50d@4x.png

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-09-17
          • 2020-09-09
          • 1970-01-01
          相关资源
          最近更新 更多