Я использую Tabhost на Android и не могу просмотреть свою активность A в Main Activity.Выдает ошибку в setIndicatorsetContent(new Intent(this, a.class))
.Какие изменения необходимы?Нужно ли изменить какой-либо код в упражнении A?
Код MainActivity
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost)findViewById(R.id.tabhost);
tabHost.setup();
//tab 1
TabHost.TabSpec spec = tabHost.newTabSpec("Tab 1");
spec.setContent(new Intent(this,a.class));
spec.setIndicator("Exams");
tabHost.addTab(spec);
//tab 2
spec = tabHost.newTabSpec("Tab 2");
spec.setContent(new Intent(this,b.class));
spec.setIndicator("Pratice");
tabHost.addTab(spec);
}
}
Журнал ошибок
Process: com.example.vivek.helloworld, PID: 17776
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.vivek.helloworld/com.example.vivek.helloworld.MainActivity}: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Caused by: java.lang.IllegalStateException: Did you forget to call 'public void setup(LocalActivityManager activityGroup)'?
at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:722)
at android.widget.TabHost.setCurrentTab(TabHost.java:388)
at android.widget.TabHost.addTab(TabHost.java:222)
at com.example.vivek.helloworld.MainActivity.onCreate(MainActivity.java:22)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)