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  确实删掉就可以运行了.但是不明白是什么原因.   如果有大神看到了,求解答一下

时间: 2024-10-19 04:41:28

No tab content FrameLayout found for id xxx的相关文章

no view for id xxx for fragment错误

用tabhost时,动态添加fragment,从网上找了好多处理结果,有的说clean一下工程,有的说是布局错误,整了半天都不行.结果是在fragment中   返回的view   View v=inflater.inflate(R.layout.fragment2, container);这个方法需要三个参数才行,添加最后一个参数 View v=inflater.inflate(R.layout.fragment2, container,false);才可以正常运行.no view for i

检查版本更新的https://itunes.apple.com/lookup?id=XXX 返回的没有数据

Looks like your app is ONLY available in Thailand storefront - so the lookup should include country code in the base lookup URL: http://itunes.apple.com/th/lookup?bundleId=com.writingfuture.where2 The alternative to using bundleId is simply looking u

a标签中href=&quot;#xxx&quot;跳到id=&quot;xxx&quot;

HTML中a标签中href="#xxx",当点击后,页面会跳转到标签中id="xxx"的地方. 同时,在URL上的后面会看到加上了#xxx,这样直接改变URL中#后面的值,然后页面就可以跳转到标签中id为这个值的地方. 测试代码: <!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>

Transaction (Process ID xxx) was deadlocked on lock

Transaction (Process ID 161) was deadlocked on lock | communication buffer resources with another process and has been chosen as the deadlock victim. Rerun the transaction. --This will cause read transactions to not take any locks and not be blocked

druid抛出异常:javax.management.InstanceAlreadyExistsException: com.alibaba.druid:type=DruidDataSource,id=xxx

参考: https://www.cnblogs.com/youzhibing/p/6826767.html 结论: 问题产生的根本原因还真是:同一实例被启动了两遍,Path为/SLBAdmin启动一次,Path为/wgp-Web启动一次, 开发过程中最好保证工程名与发布路径保证一直,避免不必要的麻烦 原文地址:https://www.cnblogs.com/moly/p/8308871.html

Mixed Content: The page at ‘https://XXX’ was loaded over HTTPS, but requested an insecure........

iframe引入视频的文件的时候报这个错 其实只要改成 加上一个s就好了  ... 原文地址:https://www.cnblogs.com/antyhouse/p/9178905.html

错误:Mixed Content: The page at ‘https://XXX’ was loaded over HTTPS, but requested an insecure.......

服务器是:https的,然后七牛云用了http,就会报错,所以,需要换成https,就可以了. 原文地址:https://www.cnblogs.com/zxyun/p/12394739.html

Android重写FragmentTabHost来实现状态保存

分类: android 2014-06-27 17:57 2077人阅读 评论(0) 收藏 举报 FragmentTabHost 最近要做一个类似QQ底部有气泡的功能,试了几个方案不太好,我想很多开发者使用TabHost都会知道它不保存状态,每次都要重新加载布局,为了保存状态,使用RadioGroup来实现,状态是可以保存了,问题是无法实现气泡功能,不能自定义布局,因为RadioGroup里面只能包含RadioButton,不然状态切换不起用作,这个可以查看RadioGroup源码,为了既能保存

Android Fragment Base

public class FragmentTabsActivity extends FragmentActivity implements OnClickListener { //定义FragmentTabHost对象 private SaveFragmentTabHost mTabHost; //定义数组来存放Fragment界面 private final Class[] fragmentArray = { A.class, B.class, C.class, D.class, E.clas