开发者

Android Dev: ClassCastException Error

I created a custom component class which is just the RadioGroup class changed to extend RelativeLayout instead of LinearLayout when I try to run my app I get this error:

06-16 00:01:17.573: ERROR/AndroidRuntime(567): Caused by: java.lang.ClassCastException: com.stickfigs.blockball.RadioGroupRelative
06-16 00:01:17.573: ERROR/AndroidRuntime(567):     at com.stickfigs.blockball.BlockBallLevelSelect.onCreate(BlockBallLevelSelect.java:38)

Line 38 refers to this line:

lsRadioGroupRelative = (RadioGroupRelative) findViewById(R.id.radioGroupRelative1);

Where that variable is defined as:

private RadioGroupRelative lsRadioGroupRelative;

Here is the layout.xml file being used in this part of the app:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:background="@drawable/background_levelselect">
    <RelativeLayout
        android:id="@+id/relativeLayout2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <com.stickfigs.blockball.RadioGroupRelative
            android:id="@+id/radioGroupRelative1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="64px"
            android:layout_marginTop="96px"
            android:orientation="horizontal">
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton1"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="1">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton2"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="2"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton1"
                android:layout_alignTop="@id/levelButton1">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton3"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="3"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton2"
                android:layout_alignTop="@id/levelButton2">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton4"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="4"
                android:layout_marginTop="32px"
                android:layout_below="@id/levelButton1"
                android:layout_alignLeft="@id/levelButton1">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton5"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="5"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton4"
                android:layout_alignTop="@id/levelButton4">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton6"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="6"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton5"
                android:layout_alignTop="@id/levelButton5">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton7"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="7"
                android:layout_marginTop="32px"
                android:layout_below="@id/levelButton4"
                android:layout_alignLeft="@id/levelButton4">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton8"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="8"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton7"
                android:layout_alignTop="@id/levelButton7">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton9"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="9"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton8"
                android:layout_alignTop="@id/levelButton8">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton10"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="10"
                android:layout_marginTop="32px"
                android:layout_below="@id/levelButton7"
                android:layout_alignLeft="@id/levelButton7">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton11"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="11"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton10"
                android:layout_alignTop="@id/levelButton10">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton12"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="12"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton11"
                android:layout_alignTop="@id/levelButton11">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton13"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="13"
                android:layout_marginTop="32px"
                android:layout_below="@id/levelButton10"
                android:layout_alignLeft="@id/levelButton10">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton14"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="14"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton13"
                android:layout_alignTop="@id/levelButton13">
            </view>
            <view
                class="com.stickfigs.blockball.BlockBallLevelSelect$RadioButtonText"
                android:button="@drawable/bb_button"
                android:id="@+id/levelButton15"
                android:layout_height="96px"
                android:layout_width="96px"
                android:textColor="#fff"
                android:text="15"
                android:layout_marginLeft="32px"
                android:layout_toRightOf="@id/levelButton14"
                android:layout_alignTop="@id/levelButton14">
            </view>
        </com.stickfigs.blockball.RadioGroupRelative>
        <Button 
            android:id="@+id/levelButtonGo"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_marginLeft="128px"
            android:layout_marginTop="22px"
            android:layout_below="@id/radioGroupRelative1"
            android:text=""
            android:background="@drawable/level_select_button_play"
            android:onClick="goClicked"/>
    </RelativeLayout>
</FrameLayout>

I'm not sure what is causing the error since I'm not trying to cast it to something it is not, what is going on?

UPDATE: Constructors:

/**
 * {@inheritDoc}
 */
public RadioGroupRelative(Context context) {
    super(context);
    //setOrientation(VERTICAL);
    init();
}

/**
 * {@inheritDoc}
 */
public RadioGroupRelative(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray attributes = context.obtainStyledAttributes(
            attrs, R.styleable.RadioGroupRelative, 0,
            android.R.style.Widget_CompoundButton_RadioButton);

    int value = attributes.getResourceId(R.styleable.RadioGroupRelative_android_checkedButton,
        View.NO_ID);
    if (value != View.NO_ID) {
        mCheckedId = value;
    }

    attributes.recycle();
    init();
}

private void init() {
    mChildOnCheckedChangeListener = new CheckedStateTracker();
    mPassThroughListener = new PassThroughHierarchyChangeListener();
    super.setOnHierarchyChangeListener(mPassThroughListener);
}

UPDATE More stacktrace:

06-16 02:18:13.814: INFO/AndroidRuntime(638): NOTE: attach of thread 'Binder Thread #3' failed
06-16 02:18:13.964: INFO/ActivityManager(58): Start proc com.stickfigs.blockball for activity com.stickfigs.blockball/.BlockBallLevelSelect: pid=645 uid=10036 gids={}
06-16 02:18:14.584: DEBUG/AndroidRuntime(645): Shutting down VM
06-16 02:18:14.584: WARN/dalvikvm(645): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-16 02:18:14.654: ERROR/AndroidRuntime(645): FATAL EXCEPTION: main
06-16 02:18:14.654: ERROR/AndroidRuntime(645): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.stickfigs.blockball/com.stickfigs.blockball.BlockBallLevelSelect}: java.lang.ClassCastException: com.stickfigs.blockball.RadioGroupRelative
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.os.Looper.loop(Looper.java:123)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread.main(ActivityThread.java:4627)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at java.lang.reflect.Method.invokeNative(Native Method)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at java.lang.reflect.Method.invoke(Method.java:521)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at dalvik.system.NativeStart.main(Native Method)
06-16 02:18:14.654: ERROR/AndroidRuntime(645): Caused by: java.lang.ClassCastException: com.stickfigs.blockball.RadioGroupRelative
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at com.stickfigs.blockball.BlockBallLevelSelect.onCreate(BlockBallLevelSelect.java:38)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.Instrumentation.callActivityOn开发者_C百科Create(Instrumentation.java:1047)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-16 02:18:14.654: ERROR/AndroidRuntime(645):     ... 11 more
06-16 02:18:14.786: WARN/ActivityManager(58):   Force finishing activity com.stickfigs.blockball/.BlockBallLevelSelect
06-16 02:18:15.326: WARN/ActivityManager(58): Activity pause timeout for HistoryRecord{44ed9600 com.stickfigs.blockball/.BlockBallLevelSelect}
06-16 02:18:19.254: INFO/Process(645): Sending signal. PID: 645 SIG: 9
06-16 02:18:19.294: WARN/InputManagerService(58): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44ea5ab8
06-16 02:18:19.584: INFO/ActivityManager(58): Process com.stickfigs.blockball (pid 645) has died.
06-16 02:18:20.106: DEBUG/SntpClient(58): request time failed: java.net.SocketException: Address family not supported by protocol
06-16 02:18:20.783: DEBUG/dalvikvm(217): GC_EXPLICIT freed 100 objects / 4192 bytes in 125ms
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜