Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android.widget.TextView cannot be cast to android.view.ViewGroup

Tags:

android

xml

So I don't see where it is casting it into android.view.ViewGroup I get this error message when I try to view my xml in the graphic view. I haven't done anything to the actual java this pertains too.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffffff"
android:orientation="vertical" >

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_gravity="center"
    android:stretchColumns="1" >

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="1.0dp"
        android:background="@drawable/list_divider_holo_light" />

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

Here I tired to make a style with these elements and it wouldn't accept it.

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="25dp"
            android:text="@string/add_alarm"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textColor="#ff505050"
            android:textSize="18.0sp" />

        <Button
            android:id="@+id/bSetTimer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="100.0dp"
            android:text="Button" />
    </TableRow>

    <Button
        android:id="@+id/bSetAlarm"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Small Text" >

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="2.0dp"
            android:background="@drawable/list_divider_holo_light" />

        <TableRow
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingTop="10dp" >

            <TextView
                android:layout_height="20.0dp"
                android:layout_gravity="center_horizontal"
                android:layout_marginLeft="40.0dp"
                android:paddingLeft="25.0dip"
                android:text="@string/alarm_volume_title" />
        </TableRow>

        <SeekBar
            android:id="@+id/default_volume_seekbar"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="15.0dp"
            android:paddingTop="2.0dip" />
    </TextView>
</TableLayout>

like image 857
domshyra Avatar asked Dec 15 '11 20:12

domshyra


2 Answers

The text view textView2 is not closed (it is just before closing the table layout), and the runtime is trying to cast it to a viewgroup in order to add the 2 table rows and seekbar.

like image 110
cheng81 Avatar answered Oct 29 '22 01:10

cheng81


You're trying to put other elements inside your TextView (@+id/textView2). That's not valid because as the error says, it's not a ViewGroup.

like image 39
kabuko Avatar answered Oct 29 '22 02:10

kabuko