Android 1.6上的java.lang.VerifyError和getActionBar()

时间:2013-04-24 09:11:38

标签: android android-actionbar verifyerror

在我的应用程序中,我使用此代码:

@TargetApi(14)
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    if(android.os.Build.VERSION.SDK_INT>=14) {
        getActionBar().setHomeButtonEnabled(false);
    }

}

但是当我在Android 1.6的模拟器中运行它时,我得到了这个错误:

04-24 09:01:16.562: E/dalvikvm(922): Could not find method com.myname.myapp.MainActivity.getActionBar, referenced from method com.myname.myapp.MainActivity.onCreate
04-24 09:01:16.562: W/dalvikvm(922): VFY: unable to resolve virtual method 1014: Lcom/myname/myapp/MainActivity;.getActionBar ()Landroid/app/ActionBar;
04-24 09:01:16.562: W/dalvikvm(922): VFY:  rejecting opcode 0x6e at 0x0155
04-24 09:01:16.562: W/dalvikvm(922): VFY:  rejected Lcom/myname/myapp/MainActivity;.onCreate (Landroid/os/Bundle;)V
04-24 09:01:16.572: W/dalvikvm(922): Verifier rejected class Lcom/myname/myapp/MainActivity;
04-24 09:01:16.572: W/dalvikvm(922): Class init failed in newInstance call (Lcom/myname/myapp/MainActivity;)
04-24 09:01:16.572: D/AndroidRuntime(922): Shutting down VM
04-24 09:01:16.572: W/dalvikvm(922): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
04-24 09:01:16.572: E/AndroidRuntime(922): Uncaught handler: thread main exiting due to uncaught exception
04-24 09:01:16.582: E/AndroidRuntime(922): java.lang.VerifyError: com.myname.myapp.MainActivity
04-24 09:01:16.582: E/AndroidRuntime(922):  at java.lang.Class.newInstanceImpl(Native Method)
04-24 09:01:16.582: E/AndroidRuntime(922):  at java.lang.Class.newInstance(Class.java:1472)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.Instrumentation.newActivity(Instrumentation.java:1097)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2316)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2417)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.ActivityThread.access$2100(ActivityThread.java:116)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.os.Looper.loop(Looper.java:123)
04-24 09:01:16.582: E/AndroidRuntime(922):  at android.app.ActivityThread.main(ActivityThread.java:4203)
04-24 09:01:16.582: E/AndroidRuntime(922):  at java.lang.reflect.Method.invokeNative(Native Method)
04-24 09:01:16.582: E/AndroidRuntime(922):  at java.lang.reflect.Method.invoke(Method.java:521)
04-24 09:01:16.582: E/AndroidRuntime(922):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
04-24 09:01:16.582: E/AndroidRuntime(922):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
04-24 09:01:16.582: E/AndroidRuntime(922):  at dalvik.system.NativeStart.main(Native Method)

当我删除行getActionBar()。setHomeButtonEnabled(false);它工作正常。如果没有删除此行,我该如何解决?

1 个答案:

答案 0 :(得分:1)

使用android-support-v4.jar就像添加ActionBar一样隐藏它。

希望您已将actiobarShareLock用于< 11 API。