java.lang.IllegalStateException .....在tabhost.add(则tabspec); [英] java.lang.IllegalStateException..... at tabhost.add(tabspec);

查看:136
本文介绍了java.lang.IllegalStateException .....在tabhost.add(则tabspec);的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨guyzz我有TabActivity如下简单的code

 公共类TabhostActivity延伸活动{
    TabHost主机;

    公共类TabhostActivity延伸活动{
    TabHost主机;
    @覆盖
    保护无效的onCreate(包savedInstanceState){
        // TODO自动生成方法存根
        super.onCreate(savedInstanceState);

        的setContentView(R.layout.tablayout);

        主机=(TabHost)findViewById(R.id.mytabhost);

        host.setup();
        意向意图=新的意图(getApplicationContext(),RatingBarActivity.class);
        TabHost.TabSpec规格= host.newTabSpec("positions").setIndicator("Positions",getResources().getDrawable(R.drawable.add)).setContent(intent);

        host.addTab(规范);
        host.setCurrentTab(0);

    }
 

和有一个简单的标签布局

 < XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent
    机器人:方向=垂直>

    < TabHost
        机器人:ID =@ + ID / mytabhost
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:填充=5DP>

        <的LinearLayout
            机器人:ID =@ + ID / linearLayout1
            机器人:layout_width =match_parent
            机器人:layout_height =match_parent
            机器人:方向=垂直
            机器人:填充=5DP>

            <的FrameLayout
                机器人:ID =@机器人:ID / tabcontent
                机器人:layout_width =match_parent
                机器人:layout_height =match_parent
                机器人:layout_weight =1
                机器人:后台=#FF0000>

            < /的FrameLayout>

            < Horizo​​ntalScrollView
                机器人:ID =@ + ID / horizo​​ntalScrollView1
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT>

                < TabWidget
                    机器人:layout_marginLeft =5DP
                    机器人:ID =@机器人:ID /标签
                    机器人:layout_width =WRAP_CONTENT
                    机器人:layout_height =WRAP_CONTENT
                    机器人:tabStripEnabled =真正的>
                < / TabWidget>
            < / Horizo​​ntalScrollView>
        < / LinearLayout中>
    < / TabHost>

< / LinearLayout中>
 

所以,请帮我在这里的code也越来越不对?我有例外,因为

  

02-23 14:09:47.920:E / AndroidRuntime(1000):java.lang.IllegalStateException:产生的原因?你忘了叫'公共无效设置(LocalActivityManager的ActivityGroup)

解决方案

要扩展活动类,尽量延长 TabActivity

如果你想使用的活动类,那么使用以下内容:

 主机=(TabHost)findViewById(R.id.tabhost); //这里tabHost将是你的Tabhost
    LocalActivityManager mLocalActivityManager =新LocalActivityManager(mActivity,假);
    mLocalActivityManager.dispatchCreate(州); //状态将被捆绑,你在的onCreate得到你的活动状态
    tabHost.setup(mLocalActivityManager);
 

Hi guyzz I have TabActivity as following simple code

public class TabhostActivity extends Activity{
    TabHost host;

    public class TabhostActivity extends Activity{
    TabHost host;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.tablayout);

        host = (TabHost) findViewById(R.id.mytabhost);

        host.setup();
        Intent intent = new Intent(getApplicationContext(), RatingBarActivity.class); 
        TabHost.TabSpec spec = host.newTabSpec("positions").setIndicator("Positions",getResources().getDrawable(R.drawable.add)).setContent(intent);

        host.addTab(spec);
        host.setCurrentTab(0);

    }

and has a simple tab layout as

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TabHost
        android:id="@+id/mytabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:padding="5dp">

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical" 
            android:padding="5dp">

            <FrameLayout
                android:id="@android:id/tabcontent"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" 
                android:background="#FF0000">

            </FrameLayout>

            <HorizontalScrollView
                android:id="@+id/horizontalScrollView1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" >

                <TabWidget
                    android:layout_marginLeft="5dp"
                    android:id="@android:id/tabs"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:tabStripEnabled="true" >
                </TabWidget>
            </HorizontalScrollView>
        </LinearLayout>
    </TabHost>

</LinearLayout>

So please help me where the code is getting wrong?? I got exception as

02-23 14:09:47.920: E/AndroidRuntime(1000): Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?

解决方案

you are extending Activity class, try extending TabActivity class

or

if you want to use the Activity class then use the following :

host = (TabHost) findViewById(R.id.tabhost); //here tabHost will be your Tabhost
    LocalActivityManager mLocalActivityManager = new LocalActivityManager(mActivity, false);
    mLocalActivityManager.dispatchCreate(state); // state will be bundle your activity state which you get in onCreate
    tabHost.setup(mLocalActivityManager);

这篇关于java.lang.IllegalStateException .....在tabhost.add(则tabspec);的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆