1. 程式人生 > >No tab content FrameLayout found for id xxx

No tab content FrameLayout found for id xxx

問題:最近在做仿微信聊天介面,使用FragmentTabHost的時候出現 No tab content FrameLayout found for id 2131492944的錯

下面是xml和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("訊息");
      
        tabHost.addTab(spec,MyFragment.class,null);

    }
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:tools="http://schemas.android.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" >
    </FrameLayout>

    <android.support.v4.app.FragmentTabHost
        android:id="@android:id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:background="#FFF1F1F1" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp" >
        </FrameLayout>
    </android.support.v4.app.FragmentTabHost>

</LinearLayout>


也查了一些資料,發現保證錯是當mRealTabContent為空時,但是上面的內容並不是空的

 private void ensureContent() {
        if (mRealTabContent == null) {
            mRealTabContent = (FrameLayout)findViewById(mContainerId);
            if (mRealTabContent == null) {
                throw new IllegalStateException(
                        "No tab content FrameLayout found for id " + mContainerId);
            }
        }
最後看網上的回答是刪掉xml中的Tabwidget  確實刪掉就可以運行了.但是不明白是什麼原因.   如果有大神看到了,求解答一下