【问题标题】:I can't load open weather map icons我无法加载打开的天气图图标
【发布时间】:2013-12-01 13:18:00
【问题描述】:

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

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

当我在 Chrome 中打开此链接时,我可以看到图像,所以我不知道为什么找不到它。

提前致谢

【问题讨论】:

标签: android


【解决方案1】:

我遇到了同样的错误,你必须删除:

con.setDoOutput(true);

因为在连接上强制使用 POST 而不是 GET,更多信息:

FileNotFoundException for HttpURLConnection in Ice Cream Sandwich

【讨论】:

    【解决方案2】:

    添加.png文件扩展名

    字符串 BASE_URL = "http://api.openweathermap.org/data/2.5/weather?q="; 私有静态字符串 IMG_URL = "http://openweathermap.org/img/w/";

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

    【讨论】:

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