Unable to display image on Android using imageview [closed]
-
26-10-2019 - |
문제
I have gone through every tutorial to display an image on an android phone from a URL. I am trying to bind an imageview object to the HTTP url but I keep getting a unable to inflate imageview class error:
02-16 23:32:50.204: E/AndroidRuntime(499): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.DBResults/com.DBResults.ContactView}: android.view.InflateException: Binary XML file line #82: Error inflating class Imageview
Theo code in my java file:
....
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;
}
My XML file looks like this (line 82 is the opening imageview tag):
<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>
해결책
it's a typo. it should be ImageView!
제휴하지 않습니다 StackOverflow