0

I am trying to fit two CheckBoxes into a single TableRow, so that they sit side by side. My program crashes at run time as soon as I try to load the view.

I previously had them each in their own row, but want to change them to fitting in the same row. I have messed with the android:layout_width feature but to no avail. This is the code I have for the TableRow.

         <TableRow>
            <CheckBox 
                android:id="@+id/circleCloseCheck"
                android:text="@string/parameters_circle_close"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />

            <CheckBox
                android:id="@+id/nwpCheck"
                android:text="@string/parameters_nwp_check"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" />
        </TableRow>

This is my LogCat...

08-23 08:59:20.760: W/dalvikvm(27494): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-23 08:59:20.768: E/AndroidRuntime(27494): FATAL EXCEPTION: main
08-23 08:59:20.768: E/AndroidRuntime(27494): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.eti.commander/my.eti.commander.Parameters}: java.lang.ClassCastException: android.widget.CheckBox
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.os.Handler.dispatchMessage(Handler.java:99)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.os.Looper.loop(Looper.java:130)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.main(ActivityThread.java:3683)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at java.lang.reflect.Method.invokeNative(Native Method)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at java.lang.reflect.Method.invoke(Method.java:507)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at dalvik.system.NativeStart.main(Native Method)
08-23 08:59:20.768: E/AndroidRuntime(27494): Caused by: java.lang.ClassCastException: android.widget.CheckBox
08-23 08:59:20.768: E/AndroidRuntime(27494):    at my.eti.commander.Parameters.populateArrayLists(Parameters.java:534)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at my.eti.commander.Parameters.onCreate(Parameters.java:54)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-23 08:59:20.768: E/AndroidRuntime(27494):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-23 08:59:20.768: E/AndroidRuntime(27494):    ... 11 more

EDIT :

Here is the information for line 534 in my Parameters.java file. Line 534 is wattVarCurrentSpinner = (Spinner) findViewById( R.id.wattVarCurrentSpinner.

    wattVarCurrentRelayList = new ArrayList<String>();
    wattVarCurrentRelayList.add( "N/A" );
    for( int i = 1; i <= 100; i++ ) {
        double temp = (i/10.0);
        wattVarCurrentRelayList.add( String.valueOf( temp ) );
    }
    wattVarCurrentSpinner = (Spinner) findViewById( R.id.wattVarCurrentSpinner );
    if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Relay" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentRelayList );
    } else if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Protector" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentProtectorList );
    } else if( RelayAPIModel.AppPrefsType.displayUnits.equals( "Percent" ) ) {
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentPercentList );      
    } else {
        RelayAPIModel.AppPrefsType.displayUnits = "Relay";
        wattVarCurrentAdapter = new ArrayAdapter<String>( this, android.R.layout.simple_spinner_item, wattVarCurrentRelayList );
    }
    wattVarCurrentAdapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    wattVarCurrentSpinner.setAdapter( wattVarCurrentAdapter );
JuiCe
  • 4,132
  • 16
  • 68
  • 119
  • There's a ClassCastException thrown in file Parameters.java at line 534. – rocky3000 Aug 23 '12 at 13:08
  • Whats in your code at Parameters.java line 534? – Barak Aug 23 '12 at 13:12
  • Um, nothing that pertains to the check boxes, but I will edit my post now and add it. Sorry, I had only changed the checkboxes in my XML file and saw it say something about a checkbox so I assumed it was an XML problem. – JuiCe Aug 23 '12 at 13:15
  • Cleaned my project and it worked :-/ – JuiCe Aug 23 '12 at 13:19

2 Answers2

1

should be android:layout_width="wrap_content" in each checkbox; you should also add android:layout_weight="1.0" to every checkbox

perfect example is here:SO answer

Community
  • 1
  • 1
przebar
  • 531
  • 1
  • 5
  • 19
1

I think you forgot to add layout_width and layout_height for TableRow Also need to change the check box layout_width to "wrap_content"

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

    <CheckBox
        android:id="@+id/circleCloseCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/parameters_circle_close" />

    <CheckBox
        android:id="@+id/nwpCheck"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/parameters_nwp_check" />
</TableRow>
Eldhose M Babu
  • 14,382
  • 8
  • 39
  • 44
  • Not sure if this was the answer, but I did this then cleaned my project and it worked. Thanks. – JuiCe Aug 23 '12 at 13:19