4

Possible Duplicate:
Anyone know what this error mean for android tabs?

I have been trying to do the TabHost tutorial in the SDK but for some reason, is appears to break. On Step 4 I copy and paste the xml code, I get an error that prevents it from inflating properly. the error is:

 Error in an XML file: aborting build.

This is in the graphical layout of the xml file.

Error during post inflation process:
TabHost requires a TabWidget with id "android:id/tabs",
View found with id "tabs" is 'com.android.layoutlib.bridge.MockView'

The xml file Itself has this in it.

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>

Am I doing something wrong?

3
  • Are you running this as a testproject or something? It looks like the TabView class is being overwritten by com.android.layoutlib.bridge.MockView. I've never seen that error before.
    – Falmarri
    Jan 6, 2011 at 21:08
  • no test project. I don't even know where com.android.layoutlib.bridge.MockView is. Wish I Did. Jan 6, 2011 at 23:15
  • here is answer of the same question.
    – ercu
    May 6, 2011 at 8:57

4 Answers 4

2

Use this template:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent">
    <LinearLayout
        android:id="@+id/tab"    android:orientation="vertical"        android:layout_width="fill_parent"   android:layout_height="fill_parent">
        <TabWidget
            android:id="@android:id/tabs"    android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"            android:layout_width="fill_parent"     android:layout_height="fill_parent">

            <LinearLayout android:id="@+id/tab1" android:layout_width="fill_parent"
             android:layout_height="fill_parent" android:orientation="vertical"/>

            <LinearLayout android:id="@+id/tab2" android:layout_width="fill_parent"
             android:layout_height="fill_parent" android:orientation="vertical"/>

</FrameLayout>
</LinearLayout>
</TabHost>
2
  • 1
    After trying what was posted by raybritton I get this error: error! RuntimeException: Could not create tab content because could not find view with id -1
    – user1030619
    Nov 5, 2011 at 0:23
  • @TiagoAfonso FYI, I just filed an Android tools bug report on this. Sep 19, 2012 at 16:15
2

See step 5 , your Activity must extend TabActivity, not Activity

Now open HelloTabWidget.java and make it extend TabActivity:

0

Switch to android target 3.0 or 3.1 in the graphical layout itself. You can find the drop down list on the top right corner

2
  • That does not seem to have any influence on the error.
    – cdonner
    Feb 12, 2012 at 16:48
  • Just to clarify, I am on the latest stack (ADT 16.0.1). I tried built targets from 1.5 all the way through 4.0.2 and always get this error.
    – cdonner
    Feb 12, 2012 at 16:56
0

You can use the updated rendering library found here: Android Tools.

Just extract the directories found in \layoutlib\[platform version] to \[sdk dir]\platforms\[platform version] and let it override the layoutlib.

Not the answer you're looking for? Browse other questions tagged or ask your own question.