2014-10-04 65 views
0

我在我的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")不起作用的鏈接。

謝謝。

+0

可以你做一個Log.e(「urltest」,items.get(position).getLink())'看到你傳遞給'decodeStream'的完整url – ashoke 2014-10-04 22:12:17

+0

感謝您的回覆,我只是這樣做,網址似乎是看起來不錯。我試圖製作一個新聞應用程序,所以這裏是鏈接,其中的一個列表項輸出: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

回答

0

是例外怎麼一回事,因爲URL類的

添加antoher捕像

catch (MalformedURLException e) { 

      e.printStackTrace(); 
     } 
0

只需單擊Alt + Enter鍵,然後再導入試捕節...幫我...

+0

您需要添加更多關於您所做的操作的詳細信息,例如您使用了哪個異常,解決問題的原因等。 – cst1992 2016-05-19 07:09:10