为什么找不到 ImageView 类?

Why the ImageView class is not found?(为什么找不到 ImageView 类?)

本文介绍了为什么找不到 ImageView 类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 main.xml 文件中插入 Imageview 时,我在创建第一个 android 应用程序(来自 pdf "Android.Application.Development.for.For.Dummies" 的静默切换模式)时遇到问题图形布局,图像不显示本身,并出现此错误:找不到以下类:- ImageView(更改为 android.widget.ImageView,修复构建路径,编辑 XML)"

i'm having troubles with creating the first android app (Silent Toggle Mode from the pdf "Android.Application.Development.for.For.Dummies" ) with inserting an Imageview in the main.xml file, when I go to the graphical layout, the image isn't showing itself and this error appears:"The following classes could not be found: - ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)"

这是我的 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>

谢谢

推荐答案

这是我最近也遇到的一个问题.这对我来说是一个误导性的错误,今天早上让我困惑了大约 30 分钟.不是Android找不到类.就是导入图片源文件有问题.

This is one issue that I have also run across recently. It was sort of a misleading error to me and kept me stumped for around 30 minutes this morning. It isn't that Android cannot find the class. It is that it is having trouble importing the image source file.

现在找不到图像的原因是我没有将源图像正确复制到目录中.我选择将源文件从另一个文件夹目录拖到适当的位置.在此过程中,它没有正确复制文件.或者它只是将其复制为其他资源的链接.

Now the reason that it is having trouble finding the image is because I did not copy the source image into the directory correctly. I have chosen to drag the source file from another folder directory into the appropriate locations. In the process, it did not copy the file over properly. Or it copied it over as just a link to the other resource.

因此,Android 不知道如何处理该资源并引发奇怪的错误.为了解决这个问题,您需要删除旧的图像源,然后用它们的等价物的直接完整副本替换它们.然后您应该会看到此错误消失,并且应用程序按照 xml 布局代码的预期工作.

As a result Android does not know what to do with the resource and throws that odd error. In order to resolve this problem, you need to delete the old image sources and then replace them with direct full copies of their equivalents. Then you should see this error go away and the application working as expected from the xml layout code.

这篇关于为什么找不到 ImageView 类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:为什么找不到 ImageView 类?

基础教程推荐