Failed to create tab content because could not find view with id -1 XML error in Android Eclipse?

I have an XML file containing TabHost. I created it directly by right-clicking on the layout map → new → Android XML → TabHost. The code looks fine, but whenever I go to the graphical location in Eclipse it gives me an error (see. Header). I am using Android 2.2. This is my XML code:

<?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="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/linearLayout1" 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" > </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="match_parent" > <LinearLayout android:id="@+id/tab1" android:layout_width="match_parent" android:layout_height="match_parent" > </LinearLayout> <LinearLayout android:id="@+id/tab2" android:layout_width="match_parent" android:layout_height="match_parent" > </LinearLayout> <LinearLayout android:id="@+id/tab3" android:layout_width="match_parent" android:layout_height="match_parent" > </LinearLayout> </FrameLayout> </LinearLayout> </TabHost> 
+4
source share
2 answers

The solution for me gave an id to each type of tab. In the following example, it was necessary to specify an id for each textView (for example, android: id = "@ + id / tab1" ...)

 <?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"> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TextView android:tag="tab1" android:text="@string/tab1" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textSize="12sp" /> <TextView android:tag="tab2" android:text="@string/tab2" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textSize="12sp" /> <TextView android:tag="tab3" android:text="@string/tab3" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textSize="12sp" /> <TextView android:tag="tab4" android:text="@string/tab4" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textSize="12sp" /> <TextView android:tag="tab5" android:text="@string/tab5" android:layout_width="wrap_content" android:layout_height="fill_parent" android:textSize="12sp" /> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/tab1" android:text="Hallo3" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/tab2" android:text="Hallo2" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/tab3" android:text="Hallo3" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/tab4" android:text="Hallo3" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <TextView android:id="@+id/tab5" android:text="Hallo3" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </FrameLayout> </LinearLayout> </TabHost> 
+4
source

I just registered the Android tools error report on this:

The following users and I saw that this error occurs when using the Graphic Layout tab of the layout editor even on the simplest and most correct layouts.

"Failed to create the contents of the tab because it could not find the view with identifier -1"

I see this in API20 when I include another XML file as a tab. If I copy and paste the contents of the include file, the error is not shown.

See the following error messages:

Failed to create tab content because could not find view with id -1 XML error in Android Eclipse?

fooobar.com/questions/1334571 / ... (see raybritton's comment for a suggested answer)

https://groups.google.com/d/topic/android-developers/DRY4fsbwgDA/discussion

+1
source

Source: https://habr.com/ru/post/1433205/


All Articles