0

我已经阅读了每个教程,以通过 URL 在 Android 手机上显示图像。我正在尝试将 imageview 对象绑定到 HTTP url,但我不断收到无法膨胀的 imageview 类错误:

02-16 23:32:50.204: E/AndroidRuntime(499): java.lang.RuntimeException: 无法启动活动 ComponentInfo{com.DBResults/com.DBResults.ContactView}: android.view.InflateException: 二进制 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>
4

1 回答 1

1

这是一个错字。它应该是 ImageView!

于 2012-02-17T00:02:02.073 回答