No tab Content framelayout found for ID xxx

Source: Internet
Author: User

Problem: Recently in The Imitation Chat interface, when using Fragmenttabhost, there is No tab content framelayout found for ID 2131492944 error


Here is the XML and main_activity

Package Com.example.scott.myweixin;import Android.os.bundle;import Android.support.v4.app.fragmentactivity;import Android.support.v4.app.fragmenttabhost;import Android.widget.tabhost.tabspec;public class MainActivity extends fragmentactivity{    private fragmenttabhost tabhost;    Private final static String tag_chat= "CHAT";    @Override    protected void onCreate (Bundle savedinstancestate)    {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);             Tabhost = (fragmenttabhost) Findviewbyid (Android. R.id.tabhost);                    Tabhost.setup (this, Getsupportfragmentmanager (), r.id.activity_home_container);              Tabspec Spec=tabhost.newtabspec (tag_chat);        Spec.setindicator ("message");              Tabhost.addtab (Spec,myfragment.class,null);    }}

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "Http://schemas.andro              Id.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent " android:orientation= "vertical" > <framelayout android:id= "@+id/activity_home_container" Android : layout_width= "fill_parent" android:layout_height= "0DP" android:layout_weight= "1" > &LT;/FRAMELAYOUT&G    T <android.support.v4.app.fragmenttabhost android:id= "@android: Id/tabhost" android:layout_width= "Match_pare            NT "android:layout_height=" Wrap_content "> <tabwidget android:id=" @android: Id/tabs " Android:layout_width= "Match_parent" android:layout_height= "Wrap_content" Android:layout_alignpar            Entbottom= "true" android:background= "#FFF1F1F1" > </TabWidget> <framelayout Android:id= "@andRoid:id/tabcontent "android:layout_width=" 0DP "android:layout_height=" 0DP "> </framelay Out> </android.support.v4.app.FragmentTabHost></LinearLayout>




Also looked up some information, found that the guarantee is wrong when the mrealtabcontent is empty, but the above content is not empty

private void Ensurecontent () {        if (mrealtabcontent = = null) {            mrealtabcontent = (framelayout) Findviewbyid ( Mcontainerid);            if (mrealtabcontent = = null) {                throw new IllegalStateException (                        "No tab content framelayout found for id" + Mcont Ainerid);            }        }



Finally, the answer on the Internet is to delete the tabwidget in the XML and it can be run. But I don't understand why. If a great God sees it, ask for answers.

No tab Content framelayout found for ID xxx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.