Program crashes when trying to display an image using ImageView
Hi all I am new to android and am having trouble doing something very simple- I would like to an an image to my xml file. Heres the xml code in configure_screen.xml (I commented out some of the irrelevant stuff) :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:id="@+id/rings"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/imageName"></ImageView> </LinearLayout>
Then, in my activity file, my onCreate() method only contains the line setContentView(R.layout.configure_screen);
I added the image to the drawable-mdpi folder. When I try to run it on the emulator it says "The application has stopped unexpectedly". The same thing happens when I replace the "@drawable/i开发者_如何学运维mageName" with "@drawable/icon".
I'm sure its something simple that I am missing, does anyone know how to fix? I can add the LogCat information if anyone is interested.
You should add your image to a new folder "drawable" by creating as you have specified drawable in src for the image view(and not drawable-mdpi). Try it......i did it and it worked well
精彩评论