I am getting the java.lang.NullPointerException on createTabContent for the following code. There are two tabspecs. When I called and set the tab , changed the tabs for the first time it is ok. But when i called again while I am on the second tab, its hit the null pointer exception for line : NoStudentText.setVisibility(View.VISIBLE);
I will show No Student Text if there is no data for the student list. It shows the text for the first time call. But If I do second time call to that tab, got the error.
tspecStudent.setContent(new TabContentFactory() {
public View createTabContent(String arg0) {
if(listStudent != null && listStudent .size() > 0) {
//show the student list
} else {
TextView noStudentText = (TextView)findViewById(R.id.NoStudentText);
noStudentText.setVisibility(View.VISIBLE);
return noStudentText;
}
}
});
I am including another xml to the main layout.
main.xml
<TabHost
android:id="@+id/tabhostMain"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
....
<include layout="@layout/tab_student" />
</TabHost>
tab_student.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView
android:id="@+id/StudentList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false" />
<TextView
android:id="@+id/NoStudentText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No Student"
android:visibility="gone" />
</FrameLayout>
Some times because of yours applied condition it couldn’t able to initialize so,
Make this variable as global like–
Initialize it in onCreate method::
Now change the visibility according to your need like this–