我在我的Android Studio項目中收到MalformedURLException一些代碼。我的目標是從網頁獲取並顯示圖像,並且URL似乎很好,但它給了我這個錯誤。Android - 未處理的java.net.MalformedURLException
我已經把代碼放在try
,catch
,但那仍然給我錯誤。 這裏就是抓住並顯示圖像的代碼:
try
{
url = new URL(items.get(position).getLink());
bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
}
catch (IOException e)
{
throw new RuntimeException("Url Exception" + e);
}
holder.itemTitle.setText(items.get(position).getTitle());;
holder.itemHolder.setBackgroundDrawable(new BitmapDrawable(bmp));
items.get(position).getLink()
是爲了讓正在顯示在ListView
,但即使像URL url = new URL("https://www.google.com")
不起作用的鏈接。
謝謝。
可以你做一個Log.e(「urltest」,items.get(position).getLink())'看到你傳遞給'decodeStream'的完整url – ashoke 2014-10-04 22:12:17
感謝您的回覆,我只是這樣做,網址似乎是看起來不錯。我試圖製作一個新聞應用程序,所以這裏是鏈接,其中的一個列表項輸出:http://www.pcworld.com/article/2691912/jpmorgan-chase-attackers-hacked-other-banks-report- says.html#tk.rss_all – Groot 2014-10-04 22:16:17