我需要为Tab创建一个片段,我的程序会崩溃。我想这是我犯的一个简单错误。必须与我的fragTab1
这就是我得到的:
Pick [Android Application]
<terminated>Pick [Android Application]
<disconnected>DalvikVM [localhost:8600]
Pick [Android Application]
DalvikVM [localhost:8600] (may be out of synch)
Thread [<1> main] (Suspended (exception RuntimeException))
<VM does not provide monitor information>
ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2295
ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2349
ActivityThread.access$700(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 159
ActivityThread$H.handleMessage(Message) line: 1316
ActivityThread$H(Handler).dispatchMessage(Message) line: 99
Looper.loop() line: 137
ActivityThread.main(String[]) line: 5419
Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]
Method.invoke(Object, Object...) line: 525
ZygoteInit$MethodAndArgsCaller.run() line: 1187
ZygoteInit.main(String[]) line: 1003
NativeStart.main(String[]) line: not available [native method]
Thread [<10> Binder_2] (Running) (may be out of synch)
Thread [<9> Binder_1] (Running) (may be out of synch)
以下是我的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_app_launch);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
ActionBar actionbar = getSupportActionBar();
actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionbar.setTitle(R.string.app_name);
ActionBar.Tab fragTab1 = actionbar.newTab().setText(R.string.tabBar_1);
Fragment fragmentQuiz = new Fragment();
fragmentQuiz.getLayoutInflater(savedInstanceState).inflate(R.layout.fragment_app_launch, null);
fragTab1.setTabListener(new TabListener(fragmentQuiz));
actionbar.addTab(fragTab1);
ActionBar.Tab fragTab2 = actionbar.newTab().setText(R.string.tabBar_2);
Fragment fragmentStatistics = new FragmentStatistics();
fragTab2.setTabListener(new TabListener(fragmentStatistics));
actionbar.addTab(fragTab2);
/*ActionBar.Tab fragTab3 = actionbar.newTab().setText(R.string.tabBar_3);
Fragment fragmentProVersion = new FragmentProVersion();
fragTab3.setTabListener(new TabListener(fragmentProVersion));
actionbar.addTab(fragTab3);*/
}