java.lang.IllegalStateException… at tabhost.add(tabspec);

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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

    

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)'?

回答1:

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); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!