我已经完成了每个教程,通过URL在Android手机上显示图像。我试图将一个imageview对象绑定到HTTP网址,但我一直无法使图像视图类错误:
02-16 23:32:50.204:E / AndroidRuntime(499):java.lang.RuntimeException:无法启动活动ComponentInfo {com.DBResults / com.DBResults.ContactView}:android.view.InflateException:Binary XML文件行#82:错误导致类Imageview
我的java文件中的Theo代码:
....
setContentView(R.layout.contact_view);
ImageView imageView = (ImageView)findViewById(R.id.ImageView1);
imageView.setImageDrawable(createDrawableFromURL("http://savagelook.com/misc/sl_drop2.png"));
....
private Drawable createDrawableFromURL(String urlString) {
Drawable image = null;
try {
URL url = new URL(urlString);
InputStream is = (InputStream)url.getContent();
image = Drawable.createFromStream(is, "src");
} catch (MalformedURLException e) {
// handle URL exception
image = null;
} catch (IOException e) {
// handle InputStream exception
image = null;
}
return image;
}
我的XML文件如下所示(第82行是开始的imageview标记):
<LinearLayout android:orientation="horizontal"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:gravity="left" android:background="@drawable/white">
<Imageview android:id="@+id/ImageView1"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
</LinearLayout>
答案 0 :(得分:1)