Android - 具有可滑动视图的选项卡布局

时间:2014-03-23 02:22:41

标签: android android-layout android-tabs

所以我在这里按照教程link

但是,最初我得到了错误:

`Call requires API level 14 (current min is 11): android.app.ActionBar#setHomeButtonEnabled for the line actionBar.setHomeButtonEnabled(false);`

然后我将@SuppressLint("NewApi")添加到了我的班级,@TargetApi(14)添加到了我的onCreate()

但我的活动仍然在同一行崩溃,并出现以下错误:

02-26 18:17:32.381: E/AndroidRuntime(19944): java.lang.RuntimeException: Unable to start activity ComponentInfo{my.package/my.package.HomeScreen}: java.lang.NullPointerException
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.os.Handler.dispatchMessage(Handler.java:102)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.os.Looper.loop(Looper.java:136)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread.main(ActivityThread.java:5017)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at java.lang.reflect.Method.invokeNative(Native Method)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at java.lang.reflect.Method.invoke(Method.java:515)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at dalvik.system.NativeStart.main(Native Method)
02-26 18:17:32.381: E/AndroidRuntime(19944): Caused by: java.lang.NullPointerException
02-26 18:17:32.381: E/AndroidRuntime(19944):    at my.package.HomeScreen.onCreate(HomeScreen.java:102)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.Activity.performCreate(Activity.java:5231)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-26 18:17:32.381: E/AndroidRuntime(19944):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
02-26 18:17:32.381: E/AndroidRuntime(19944):    ... 11 more

1 个答案:

答案 0 :(得分:0)

在清单中将最小api版本设置为14,如下所示:android:minSdkVersion="14"并查看会发生什么。也许您正在测试的仿真器/设备具有较低的api。

否则使用ActionBarSherlock来支持较低的apis。