2011-06-10 95 views
0

它給了我下面的錯誤當我嘗試當我嘗試加載圖像到機器人加載圖像,未知主機異常Android中

06-10 11:08:50.217: WARN/System.err(868): java.net.UnknownHostException: nopsa.hiit.fi 
06-10 11:08:50.217: WARN/System.err(868):  at java.net.InetAddress.lookupHostByName(InetAddress.java:497) 
06-10 11:08:50.217: WARN/System.err(868):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294) 
06-10 11:08:50.217: WARN/System.err(868):  at java.net.InetAddress.getAllByName(InetAddress.java:256) 
06-10 11:08:50.237: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69) 
06-10 11:08:50.237: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48) 
06-10 11:08:50.272: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322) 
06-10 11:08:50.272: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89) 
06-10 11:08:50.272: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285) 
06-10 11:08:50.277: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267) 
06-10 11:08:50.277: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1018) 
06-10 11:08:50.297: WARN/System.err(868):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:512) 

我試圖訪問該文件是 http://nopsa.hiit.fi/pmg/viewer/images/thumb_132750728_8f0342f1ac_t.jpg

和我裏面的onDraw使用的代碼()是繼

try { 
    URL url = new URL(collectable.getIcon_url());      
    HttpURLConnection connection = (HttpURLConnection) url.openConnection(); 
    InputStream is = connection.getInputStream(); 
    Bitmap img = BitmapFactory.decodeStream(is);     
    canvas.drawBitmap(img, 100, 100 , null); 
} catch (Exception e) { 
    Log.d(TAG, "Image Load Failed"); 
    e.printStackTrace(); 
} 
+0

而且你ofcourse有設備上的互聯網連接?只需檢查:-) – 2011-06-10 11:26:41

+0

collectable.getIcon_url()是否返回正確的字符串?它是否與另一個模擬網址兼容?你必須測試這個。 – Egor 2011-06-10 11:27:37

+0

其實,即時通訊模擬器上運行它?我以爲,因爲電腦有互聯網模擬器也有它 – dinesh707 2011-06-10 11:28:00

回答

2

如果您在測試模擬器,你確定你有互聯網,嘗試重新啓動仿真器。有時模擬器崩潰。我經常遇到這個錯誤。

+0

是的,嘗試重新啓動,我也經常這樣做。啓用快照,因此循環emu需要較少的時間。 – dmon 2011-06-10 11:31:37

+0

我重新啓動了3次,沒有運氣。但是,當我通過模擬器轉到互聯網,它的工作原理 – dinesh707 2011-06-10 11:44:27

+1

用其真實IP地址替換主機名稱nopsa.hiit.fi。你有聯繫嗎?可能問題出在android的dns緩存中。這是一個新的域名? – 2011-06-10 11:50:46

2

Permission Denied發生是因爲我沒有在清單中設置權限。

我只是需要加入:

<uses-permission android:name="android.permission.INTERNET" /> 
相關問題