Karthik Balakrishnan
Karthik Balakrishnan

Reputation: 4393

Tabs in different layout files are causing the app to crash

I'm using different layout files for individual tabs for my main activity. I have changed quite a bit. I tried making tab2.xml's relative layout to wrap_content initially, but that didn't help. I changed the id of the include file and called that in my java code, didn't work. I tried the most obvious ones. Now, I have no idea what's wrong. Also, I did do this earlier and it worked fine with tab2.xml's height and width being in match_parent mode. The program app now though. The line of code show in the debug console is "setContentView(R.layout.activity);". So, it's definitely the layout files and nothing in the code causing the app to crash.

Here's the main activity's xml code: "activity.xml"

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:context=".CleanUp" >

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@style/MyTheme" >

        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >


            <include layout="@layout/tab2"/>            


        </FrameLayout>

    </LinearLayout>
</TabHost>

</RelativeLayout>

Here's tab2.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
                android:id="@+id/tab2"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".CleanUp"  >

<EditText
    android:id="@+id/editText1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_toRightOf="@+id/textView1"
    android:layout_marginTop="40dp"
    android:layout_marginRight="20dp"
    android:inputType="text"
    android:ems="10" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/editText1"
    android:layout_alignBottom="@+id/editText1"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="20dp"
    android:layout_marginRight="10dp"
    android:text="Custom extension:"
    android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="Clean" />

</RelativeLayout>

Here's the code I'm using for the tabs in my Activity class:

TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();
    TabSpec tab1 = tabHost.newTabSpec("Clean Up");
    tab1.setIndicator("Clean up");
    tab1.setContent(R.id.tab2);
    tabHost.addTab(tab1);

LOGCAT ERRORS

http://pastebin.com/DcXGdCuF

Upvotes: 0

Views: 99

Answers (1)

Cat
Cat

Reputation: 67522

This LogCat line:

Caused by: android.content.res.Resources$NotFoundException: Resource is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f050002 a=-1 r=0x7f050002}

Leads me to believe your error is on this line:

android:background="@style/MyTheme"

You cannot use a @style/X attribute as a background. You must either pass it a drawable:

android:background="@drawable/MyDrawable"

Or use it as a style, properly:

style="@style/MyTheme"

Upvotes: 2

Related Questions