Why is the ImageView class not found?

I had problems creating the first Android application (Silent Toggle Mode from pdf "Android.Application.Development.for.For.Dummies") with the Imageview inserted into the main.xml file, when I go to the graphic layout, the image does not appear , and this error appears: "The following classes were not found: - ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)"

this is my xml code

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:contentDescription="@string/hello_world" android:orientation="vertical" tools:context=".MainActivity" > <EditText android:id="@+id/edit_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/edit_message" /> <ImageView android:id="@+id/phone_icon" android:contentDescription="@string/description" android:layout_width="wrap_content" android:scaleType="fitXY" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:src="@drawable/phone_on" /> <Button android:id="@+id/toggleButton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/ToggleSilentMode" /> </LinearLayout> 

thanks

+4
source share
3 answers

This is one of the problems I have recently encountered. This was a kind of misleading mistake for me and kept me at a standstill for about 30 minutes this morning. It's not that Android cannot find the class. This is due to the fact that he was having problems importing the original image file.

Now, the reason he has problems finding the image is because I did not copy the original image to the directory correctly. I decided to drag the source file from another folder directory to the appropriate places. However, he did not copy the file properly. Or he copied it as a link to another resource.

As a result, Android does not know what to do with the resource and throws this odd error. To solve this problem, you need to remove the old image sources and then replace them with direct full copies of their equivalents. Then you should see that this error disappears and the application works as expected from the xml layout code.

+6
source

I ran into the same problem once. To get this, I replaced all existing images, now it worked.

0
source

I had the same problem when a new ImageView was added in my xml with src image.

I tried to open this image using Photoshop and get a "module format error". Thus, the image was damaged. The problem was solved by creating a new image similar to the first.

Hope it works :)

0
source

All Articles