我的服務器上有一張圖片。該圖像的URL是這樣的: http://www.mydomain.com/123456uploaded_image.jpg使用URL設置ImageView
我想將此圖像設置爲我的ImageView。這裏是我試過的代碼:
try{
String url1 = myeventimagearray[position];
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = (InputStream) con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
iveventimg.setImageBitmap(bmp);
else
Log.i("Image","Not set");
} catch(Exception e) {
e.printStackTrace();
}
當我嘗試這一點,我的ImageView是空的,也就是說,它不設置圖像視圖和我得到了我的logcat這個系統錯誤:
java.lang.ClassCastException:libcore.net.http.FixedLengthInputStream不能轉換到com.example.eventnotifier.Base64 $ InputStream的
Base46.java是我從網上得知編碼找到的文件和解碼並來自Base64符號。
任何想法,爲什麼我得到這個System.error?
謝謝
非常感謝!它的工作:) – Nemin 2013-05-05 21:29:12
乾杯..快樂編碼:) – 2013-05-05 21:42:49