I made a tabHost in an Activty and everytime it reaches the .addTab(Spec) it crashes.
I created the tab host in the Activity like so:
peopleTabHost = new TabHost(this);
and then I use a method to add the tab (I can do that because I defined the peopleTabHost as final outside of the onCreat)
private void CreateNewTab(String tagName, String displayedName, Class<?> intentClass)
{
Intent intent = new Intent().setClass(this, intentClass);
TabHost.TabSpec spec = peopleTabHost.newTabSpec(tagName).setIndicator(displayedName);
spec.setContent(intent);
peopleTabHost.addTab(spec);
}
Thanks
I second sianis’ answer, but I’m also adding that it might be crashing because you are not initializing (or at least not showing) the tabhost.
Try to run
peopleTabHost.setup();right after calling the constructor.