當我試圖讓我的活動中的選項卡主機顯示錯誤,你忘記打電話public void setup(LocalActivityManager activityGroup)
?進入我的活動的Tabhost錯誤
public class MainActivity extends FragmentActivity {
private Resources res;
private TabHost tabHost;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// tabHost = getTabHost();
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
res = getResources();
Intent intentContact = new Intent().setClass(this,
tabOne_Activity.class);
TabSpec tabSpecContact = tabHost.newTabSpec("Chat")
.setIndicator("", res.getDrawable(R.drawable.ic_launcher))
.setContent(intentContact);
tabHost.addTab(tabSpecContact);
Intent intentChat = new Intent().setClass(this, tabTwo_Activity.class);
TabSpec tabSpecChat = tabHost.newTabSpec("Chat")
.setIndicator("", res.getDrawable(R.drawable.ic_launcher))
.setContent(intentChat);
tabHost.addTab(tabSpecChat);
Intent intentProfile = new Intent().setClass(this,
tabThree_Activity.class);
TabSpec tabSpecProfile = tabHost.newTabSpec("Chat")
.setIndicator("", res.getDrawable(R.drawable.ic_launcher))
.setContent(intentProfile);
tabHost.addTab(tabSpecProfile);
tabHost.setCurrentTab(2);
}
}
移動'tabHost.setup(;'最後設置的所有選項卡後 – 2015-02-06 06:46:41
更換Tabhost findviewById本mTabHost =( FragmentTabHost)findViewById(android.R.id.tabhost); – 2015-02-06 06:56:34
@MD然後它顯示空指針異常導致:java.lang.NullPointerException .TabHost.addTab(TabHost.java:236) – 2015-02-06 06:56:48