2013-04-24 69 views
2

在我的應用程序正在使用此代碼:java.lang.VerifyError的,並在Android getActionBar()1.6

@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);它工作正常。如何解決這個問題而不刪除這條線?

+0

[VerifyError部署在API 1.6上]的可能重複(http://stackoverflow.com/questions/6495007/verifyerror-deploying-on-api-1-6) – 2013-04-25 13:16:08

回答

1

使用android-support-v4.jar它就像在添加ActionBar之後隱藏那樣。

希望你已使用actiobarShareLock爲< 11 API。