使用ImageView控件在Android中创建错误

时间:2012-01-19 10:17:19

标签: java android android-layout android-imageview

我在android中创建一个应用程序。当我在将ImageView控件插入我的应用程序后尝试运行应用程序时,我在logCat中收到以下错误:

java.lang.RuntimeException: Unable to start activity   
ComponentInfo{com.bdisys.android.wsaccess/com.bdisys.boinfoportal.ui.FirstAppUI}: 
java.lang.ClassCastException: android.widget.TextView

在我将一个ImageView插入layout / main.xml后,以下内容就像是一个警告。

The following classes could not be found:
- ImageView (Change to android.widget.ImageView, Fix Build Path, Edit XML)

在插入ImageView之后的xml代码部分之后。

<TableRow  
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="right">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/favicon" />

    </TableRow>

有人可以说出这个错误的原因吗?

我对此并不了解。请帮忙。提前谢谢。

3 个答案:

答案 0 :(得分:2)

您正在尝试将TextView投射到ImageView。检查您的资源xml。

答案 1 :(得分:2)

我在ImageView遇到了同样的问题,The following classes...

的设计标签中显示了main.xml消息

在我的情况下,问题是drawable没有扩展名,但它出现在@drawable/部分,并且也出现在自动完成中,好像没有任何错误。

但是无法提供有关classcast异常的任何信息。

总结:确保您的favicon文件具有正确的扩展名

答案 2 :(得分:0)

如果你有这样的代码

ImageView img;
img = (ImageView) findViewById(R.id.TextView1);

更改为

TextView txt;
txt = (TextView) findViewById(R.id.TextView1);