Android 类强制转换异常问题

Android 类强制转换异常问题,android,xml,exception,Android,Xml,Exception,在我的android应用程序中看到奇怪的行为。我的android xml中有一个仪表和一个图像视图。它工作得很好,只是在我的xml图形视图中更改小部件的位置,我得到了这个ClassCastException.下面是我的xml文件 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" an

在我的android应用程序中看到奇怪的行为。我的android xml中有一个仪表和一个图像视图。它工作得很好,只是在我的xml图形视图中更改小部件的位置,我得到了这个
ClassCastException.
下面是我的xml文件

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/halo"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".hello" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="perform" />

    <org.codeandmagic.android.gauge.GaugeView
        android:id="@+id/gauge_view1"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_alignLeft="@+id/button1"
        android:layout_alignParentTop="true"
        android:layout_weight="1" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="130dp"
        android:layout_height="130dp"
        android:layout_alignLeft="@+id/gauge_view1"
        android:layout_centerVertical="true"
        android:src="@drawable/images" />

</RelativeLayout>

有人能解释一下为什么我的情况会这样吗?然后最大的问题是小部件的位置与它有什么关系???

进行项目清理。这是一个普遍的问题

Eclipse-Project-Clean-选择您的项目-Ok

我不知道为什么会发生这种情况,但我想有时候,当您移动视图时,它会在XML上移动,但不会在编译的代码上移动。通过项目清理,重新生成编译后的代码,然后正确放置。

初始化“org.codeandmagic.android.gauge.GaugeView”自定义类的对象时,强制转换存在问题。否则,如果存在具有正确包名的cutom类,则xml是正确的

查看初始化或请在此处添加该代码

这是一个常见问题。 清理一个项目,并检查java文件中的变量类型转换

例如

Button b=(Button)findViewById(R.id.button1);


也许可以解决这个问题。

您应该检查在哪里定义小部件 像


请将您的
ComponentInfo
活动的代码粘贴到您使用
org.codeandmagic.android.gauge.GaugeView
的位置?您是否正在按GaugeView按钮发布您的活动代码谢谢我解决了它!答案是正确的!非常感谢。决定!:D+1。但我很想知道为什么会这样!我从来没有将仪表转换为图像视图,那么logcat有什么问题吗?我猜,您在某个时候交换了XML中的按钮和仪表视图。@Baba我真的不知道,我知道的是这种情况刚刚发生。如果你移动视图,会有很多。如果这解决了您的问题,请接受正确的答案。我有单独的答案!
Button b=(Button)findViewById(R.id.button1);
GaugeView gv=(GaugeView)findViewById(R.id.gauge_view1);
Button btn1=(Button)findViewById(R.id.button1);
GaugeView gv=(GaugeView)findViewById(R.id.gauge_view1);
Imageview iv=(ImageView)findViewById(R.id.imageView1);