Java Android.widget.RelativeLayout无法强制转换为Android.widget.ImageView

Java Android.widget.RelativeLayout无法强制转换为Android.widget.ImageView,java,android,android-layout,runtime-error,classcastexception,Java,Android,Android Layout,Runtime Error,Classcastexception,我正在尝试获取XML布局文件中定义的ImageView实例: <RelativeLayout android:id="@+id/visual_compass_container" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id

我正在尝试获取XML布局文件中定义的ImageView实例:

<RelativeLayout
    android:id="@+id/visual_compass_container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/output_container" >

    <ImageView
        android:id="@+id/visual_compass"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:contentDescription="Compass"
        android:scaleType="fitStart"
        android:src="@drawable/compass_rose" />

</RelativeLayout>
第57行是:

compassView = (ImageView) findViewById(R.id.visual_compass);
我不明白为什么会抛出这个错误;我看不出那段代码有什么问题。还有谁知道吗


谢谢您,Felix D.

请确保您的代码中的
compassView
仅为
ImageView
变量,并尝试作为

  ImageView compassView = (ImageView) findViewById(R.id.visual_compass); 

如果一切都正确,那么尝试从菜单
project->clean.
Proejct->Build

中再次清理和构建项目。您是否尝试清理和重建项目?您的确切意思是什么?我正在使用Eclipse:那么我应该创建一个新的PEObject并将所有修改过的文件从旧的ont复制到它吗?不,Eclipse中有一个选项-clean,它将删除所有生成的文件,然后您必须重新构建,这将重新生成它们。(Project->Clean,如果您不知道的话)您确定您没有意外地编写compassView的
RelativeLayout[…]?如果没有,那么清理项目可能会像其他人已经建议的那样有所帮助。好的,谢谢你的快速评论。我会试着清理这个项目。把我的结果贴在这里@艾哈迈德,是的,我确定。好的!这很有帮助。谢谢你。但我认为这个项目是在清理后自动重建的。Eclipse会自动检查演员阵容是否正确。。。
  ImageView compassView = (ImageView) findViewById(R.id.visual_compass);