나는 서버에있는 그림을 검색하려고합니다. 그래서 나는 다음과 같은 방법 일로를 검색하기 위해 노력하고있어 :안드로이드 애플 리케이션에 그림을 표시
ImageView e = (ImageView) findViewById(R.id.img);
e.setImageBitmap(downloadBitmap(img_url(param1.img)));
하고 XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<!-- Name Label -->
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/picture">
</ImageView>
:
static Bitmap downloadBitmap(String url) {
final AndroidHttpClient client = AndroidHttpClient.newInstance("Android");
final HttpGet getRequest = new HttpGet(url);
try {
HttpResponse response = client.execute(getRequest);
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
Log.w("ImageDownloader", "Error " + statusCode + " while retrieving bitmap from " + url);
return null;
}
final HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream inputStream = null;
try {
inputStream = entity.getContent();
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
return bitmap;
} finally {
if (inputStream != null) {
inputStream.close();
}
entity.consumeContent();
}
}
} catch (Exception e) {
// Could provide a more explicit error message for IOException or IllegalStateException
getRequest.abort();
} finally {
if (client != null) {
client.close();
}
}
return null;
}
을 그리고 다른 방법으로 나는 다음 두 줄이
그러나 그림이 표시되지 않고 오류가 발생하지 않습니다. 누구든지 내가 뭘 잘못하고 있다고 말할 수 있습니까?
제공하신 URL이 정확한가요? 그리고 실제로 이미지가 포함되어 있습니까? –
안녕 Vishwa. 예, 저는 URL과 이미지에 대해 100 % 확신합니다. –