我试图隐藏我的操作栏。请检查我的代码。它似乎不起作用。我还在代码底部列出了我的 LOGCAT。请帮忙。
MainActivity.java
public class MainActivity extends SherlockFragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
ActionBar actionBar = getSupportActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
actionBar.setDisplayShowTitleEnabled(true);
Tab tab = actionBar.newTab()
.setText("Android")
.setTabListener(new AndroidFragment())
.setIcon(R.drawable.android);
actionBar.addTab(tab);
tab = actionBar.newTab()
.setText("Apple")
.setTabListener(new AppleFragment())
.setIcon(R.drawable.apple);
actionBar.addTab(tab);
}
}
日志猫:
10-06 18:17:25.781: E/AndroidRuntime(15962): FATAL EXCEPTION: main
10-06 18:17:25.781: E/AndroidRuntime(15962): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.actionbarsherlocknavtab/in.wptrafficanalyzer.actionbarsherlocknavtab.MainActivity}: java.lang.NullPointerException
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1970)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread.access$600(ActivityThread.java:127)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1161)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.os.Looper.loop(Looper.java:137)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread.main(ActivityThread.java:4512)
10-06 18:17:25.781: E/AndroidRuntime(15962): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 18:17:25.781: E/AndroidRuntime(15962): at java.lang.reflect.Method.invoke(Method.java:511)
10-06 18:17:25.781: E/AndroidRuntime(15962): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:982)
10-06 18:17:25.781: E/AndroidRuntime(15962): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:749)
10-06 18:17:25.781: E/AndroidRuntime(15962): at dalvik.system.NativeStart.main(Native Method)
10-06 18:17:25.781: E/AndroidRuntime(15962): Caused by: java.lang.NullPointerException
10-06 18:17:25.781: E/AndroidRuntime(15962): at in.wptrafficanalyzer.actionbarsherlocknavtab.MainActivity.onCreate(MainActivity.java:19)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.Activity.performCreate(Activity.java:4465)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
10-06 18:17:25.781: E/AndroidRuntime(15962): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1934)
10-06 18:17:25.781: E/AndroidRuntime(15962): ... 11 more