2011-05-26 50 views
0

您好所有我想從網頁加載圖像,但我得到異常類轉換異常,而從webbu加載圖像

java.lang.ClassCastException: org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl$LimitedInputStreamm 

我加載圖像的代碼是

private Drawable loadImageFromWebOperations(String url) 
    { 
       Log.i("WHERE","MenuPage loadImageFromWebOperations()"); 
      try 
       { 
         InputStream is = (InputStream) new URL(url).getContent(); 
         Drawable d = Drawable.createFromStream(is, "src name"); 
         return d; 
       } 
      catch (Exception e) 
       { 
         System.out.println("loadImageFromWebOperations ="+e); 
         Log.v("EXCEPTION AT ","FriendActivity loadImageFromWebOperations()"); 
         return null; 
       } 
     } 

plz幫助我 在此先感謝

回答

0

使用此方法下載圖像。

HttpGet httpRequest = null; 
      httpRequest = new HttpGet(url); 
      HttpClient httpclient = new DefaultHttpClient(); 
      HttpResponse response = (HttpResponse) httpclient.execute(httpRequest); 
      HttpEntity entity = response.getEntity(); 
      BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); 
      InputStream instream = bufHttpEntity.getContent(); 
      bitmap= BitmapFactory.decodeStream(instream); 
+0

謝謝你的回覆,但我仍然沒有得到加載的圖像在我的imgeview,而我打印在logcat中,圖像url是從服務器給出null,並且圖像未加載。 – MJBoss 2011-05-26 12:49:47