Join activitytabHost. Setup (enclosing getLocalActivityManager ()); Is ok, but this changed after teacher_tab. Setup (enclosing getLocalActivityManager ()); It will report null pointer error "Java. Lang. NullPointerException: Attempt to invoke virtual method 'void android. Widget. The TabHost. Setup (android. App. LocalActivityManager)' on a null object reference",
Below is a Java code
Public class TeacherActivity extends ActivityGroup {
Private Context Context=TeacherActivity. This;
Private ListListMyCourses=new ArrayList<> (a);
Void getMyCourses () {
ListMycourses=CMSClient. GetMyCourses (SystemConfig. Username);
ListMyCourses. The clear ();
C: for (CourseSummary mycourses) {
ListMyCourses. Add (c);
}
}
@ Override
Protected void onCreate (Bundle savedInstanceState) {
Super. OnCreate (savedInstanceState);
TabHost teacher_tab=the findViewById (R.i which abhost_teacher);
Teacher_tab. Setup (enclosing getLocalActivityManager ());
//TabHost teacher_tab=getTabHost ();
//LayoutInflater. The from (this). Inflate (R.l ayout. Activity_teacher_main, teacher_tab. GetTabContentView (), true);
Teacher_tab. AddTab (teacher_tab newTabSpec (" taba "). SetIndicator (" my course "). SetContent (R.i which eacher_mycourses));
Teacher_tab. AddTab (teacher_tab newTabSpec (" firm "). SetIndicator (" course maintenance "). SetContent (new Intent (this, TeacherActivity_courserepair. Class)));
Teacher_tab. AddTab (teacher_tab newTabSpec (" tabc "). SetIndicator (" schedule view "). SetContent (R.i which eacher_coursetable));
//I of course TAB
ListView listview_mycourses=the findViewById (R.i d.l ist_view_teacher_course);
GetMyCourses ();
for(int i=0; iLog i. (" cmstag, "listMyCourses. Get (I). CourseName);
}
MyCoursesAdapter MDP=new MyCoursesAdapter (context, R.l ayout. Listview_sub_mycourse, listMyCourses);
Listview_mycourses. SetAdapter (MDP);
Listview_mycourses. SetOnItemClickListener (new AdapterView. OnItemClickListener () {
@ Override
Public void onItemClick (AdapterView<?> The parent, View View, int position, long id) {
CourseSummary myCourse=listMyCourses. Get (position);
Intent Intent=new Intent (context, CourseDetailsActivity. Class);
Intent. PutExtra (" course_id "myCourse. CourseId);
The context. StartActivity (intent);
}
});
//label switching event handling, setOnTabChangedListener
Teacher_tab. SetOnTabChangedListener (new TabHost. OnTabChangeListener () {
@ Override
Public void onTabChanged (String tabId) {
If (tabId. Equals (" taba ")) {//the first tag
}
If (tabId. Equals (" firm ")) {//course maintenance
}
If (tabId. Equals (" tabc ")) {//schedule to see
}
}
});
}
}
Here is the error message
E/AndroidRuntime: FATAL EXCEPTION: the main
Process: cn.edu.njrts.cms, PID: 8947
Java. Lang. RuntimeException: Unable to start the activity ComponentInfo {cn.edu.njrts.cms/cn.edu.njrts.cms.TeacherActivity} : Java. Lang. NullPointerException: Attempt to invoke virtual method 'void android. Widget. The TabHost. Setup (android. App. LocalActivityManager)' on a null object reference
. An android app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2665)
. An android app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2726)
. An android app. ActivityThread. - wrap12 (ActivityThread. Java)
An android. App. ActivityThread $H.h andleMessage (ActivityThread. Java: 1477)
An android. OS. Handler. DispatchMessage (Handler. Java: 102)
. An android OS. Stars. Loop (154). Which Java:
. An android app. ActivityThread. Main (6119) ActivityThread. Java:
The at Java. Lang. Reflect. Method. Invoke (Native Method)
At com. Android. Internal. OS. $MethodAndArgsCaller ZygoteInit. Run (ZygoteInit. Java: 886)
At com. Android. Internal. OS. ZygoteInit. Main (ZygoteInit. Java: 776)
Under Caused by: Java. Lang. NullPointerException: Attempt to invoke virtual method 'void android. Widget. The TabHost. Setup (android. App. LocalActivityManager)' on a null object reference
The at cn.edu.njrts.cms.TeacherActivity.onCreate (TeacherActivity. Java: 38)
. An android app. Activity. PerformCreate (6679) Activity. Java:
. An android app. Instrumentation. CallActivityOnCreate (1118) Instrumentation. Java:
. An android app. ActivityThread. PerformLaunchActivity (ActivityThread. Java: 2618)
. An android app. ActivityThread. HandleLaunchActivity (ActivityThread. Java: 2726)
. An android app. ActivityThread. - wrap12 (ActivityThread. Java)
An android. App. ActivityThread $H.h andleMessage (ActivityThread. Java: 1477)
An android. OS. Handler. DispatchMessage (Handler. Java: 102)
. An android OS. Stars. Loop (154). Which Java:
. An android app. ActivityThread. Main (6119) ActivityThread. Java:
The at Java. Lang. Reflect. Method. Invoke (Native Method)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull