我正在从网址检索图片并将其显示在imageview
中。但是我的代码给了我无效的消息。
ImageView imageview = (ImageView) findViewById(R.id.imageView1);
try {
Uri uri=Uri.parse("http://10.0.2.2:8083/call/rahul.jpg");
// uri.buildUpon().appendQueryParameter("key", "Android developer");
URI u = new URI(uri.toString());
System.out.println("path is "+u);
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet();
httpget.setURI(u);
//httpget.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httpget);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Bitmap bitmap = BitmapFactory.decodeStream(is);
imageview.setImageBitmap(bitmap);
} catch(Exception e) {
System.out.println("this is the error "+e.getMessage());
}
logcat: -
02-04 19:32:35.355: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:35.355: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:35.895: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:35.915: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:35.915: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:36.425: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:36.445: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:36.445: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:36.992: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:37.005: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:37.005: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:37.565: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:37.585: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:37.585: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:38.105: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:38.125: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:38.125: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:38.645: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:38.665: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:38.665: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:39.175: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:39.195: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:39.205: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
02-04 19:32:39.695: I/dalvikvm(679): threadid=3: reacting to signal 3
02-04 19:32:39.716: D/dalvikvm(679): threadid=1: still suspended after undo (sc=1 dc=1)
02-04 19:32:39.716: I/dalvikvm(679): Wrote stack traces to '/data/anr/traces.txt'
答案 0 :(得分:0)
试试这个:
ImageView imageview = (ImageView) findViewById(R.id.imageView1);
mBitmap = BitmapFactory.decodeStream((InputStream) new URL(http://10.0.2.2:8083/call/rahul.jpg).getContent());
imageview .setImageBitmap(mBitmap);
答案 1 :(得分:0)
好吧,既然你已经说过我建议的效果很好,我想我应该把它作为答案提交。我发现你似乎距离工作解决方案还有很长的路要走,因为在你想要使用诸如android-query之类的库之前,这个问题已经解决了很多次。我与该图书馆没有任何关系 - 我以前只是自己使用过它。此外,由于我在技术上没有回答你的问题,虽然我解决了你的问题,但我最好再为绿色标记做一点,是吗?
您对该库的使用看起来很好,you don't need to call recycle(您可以轻松地在Google上找到它)。请注意,您也可以使用它来做很多其他很好的事情,例如加载时淡入图像,如果它们非常大则加载时对它们进行缩减,等等。你可以找到很多examples on the android-query site。
关于它是否是免费的查询,许可证在我链接到的主页面上,在靠近顶部的左侧。这是Apache License 2.0。简而言之,只要您在应用程序的任何发行版中包含Apache许可证的副本,并且明确提及您在许可证下使用的任何库,此许可证允许您自由使用该库。或者你可以read the blurb from their FAQ。您通常会在应用程序中放置一个关于此类事物的屏幕,清楚地表明您正在使用Apache 2.0许可证下的android-query库,以及可查看的许可证副本。适当的归属:我认为您同意这个许可证可以在本许可证下找到很多有用的东西:o)
祝你的应用好运!