在我的 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>
logcat 在应用程序崩溃时向我显示以下内容:
09-18 11:02:01.411: E/AndroidRuntime(21312): FATAL EXCEPTION: main
09-18 11:02:01.411: E/AndroidRuntime(21312): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hello.hello}: java.lang.ClassCastException: android.widget.Button cannot be cast to org.codeandmagic.android.gauge.GaugeView
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2194)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2229)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.app.ActivityThread.access$600(ActivityThread.java:139)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1261)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.os.Handler.dispatchMessage(Handler.java:99)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.os.Looper.loop(Looper.java:154)
09-18 11:02:01.411: E/AndroidRuntime(21312): at android.app.ActivityThread.main(ActivityThread.java:4945)
09-18 11:02:01.411: E/AndroidRuntime(21312): at java.lang.reflect.Method.invokeNative(Native Method)
09-18 11:02:01.411: E/AndroidRuntime(21312): at java.lang.reflect.Method.invoke(Method.java:511)
09-18 11:02:01.411: E/AndroidRuntime(21312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
09-18 11:02:01.411: E/AndroidRuntime(21312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
09-18 11:02:01.411: E/AndroidRuntime(21312): at dalvik.system.NativeStart.main(Native Method)
09-18 11:02:01.411: E/AndroidRuntime(21312): Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to org.codeandmagic.android.gauge.GaugeView
任何人都可以解释为什么会在我的情况下发生吗?然后最大的问题是小部件的位置与它有什么关系?