I'm trying to create tabs based on an array returned by the database. However, I'm getting the following error.
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setVisibility(int)' on a null object reference
The code that I'm using is below, the array subAreas has already 3 values.
public class ExtintorFragment extends Fragment {
private LinearLayout ll;
private TabHost tabs;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ll = (LinearLayout) inflater.inflate(R.layout.fragment_criterios, container, false);
setHasOptionsMenu(true);
tabs = (TabHost) ll.findViewById(R.id.tabHost);
tabs.setup();
String[] subAreas;
EquipamentosSubAreaDbAdapter mDb = new EquipamentosSubAreaDbAdapter(getContext());
mDb.open();
subAreas = mDb.getSubareasEquipamento("Extintores");
mDb.close();
for (int i = 0; i < subAreas.length; i++) {
TabHost.TabSpec spec = tabs.newTabSpec(subAreas[i]);
spec.setIndicator(subAreas[i]);
spec.setContent(new TabHost.TabContentFactory() {
@Override
public View createTabContent(String tag) {
return null;
}
});
tabs.addTab(spec);
}
return ll;
}
@Override
public void onActivityCreated (Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
}
}
Also, could you give me tips to create a listView as TabContent.
Thank you