can't catch java.lang.VerifyError

I'm getting this error: "Uncaught handler: thread main exiting due to uncaught exception java.lang.VerifyError"

It's only happening on 1.6. Android 2.0 and up doesn't have any problems, but that's the main point of all.

I Can't catch the Error/Exception (VerifyError), and I know it's being caused by calling isInitialStickyBroadcast() which is not available in SDK 4, that's why it's wrapped in the SDK check. I just need this BroadcastReceiver to work on 2.0+ and not break in 1.6, it's an app in the market, the UNDOCK feature is needed for users on 2.0+ but obviously not in 1.6 but there is a fairly amount of users still on 1.6.

How to fix?


private BroadcastReceiver mUndockedReceiver = new BroadcastReceiver()
      public void onReceive(Context context, Intent intent) 
          if (Build.VERSION.SDK_INT >= 5)
              if (!isInitialStickyBroadcast()) {
                  int dockState = intent.getExtras().getInt("android.intent.extra.DOCK_STATE", 1);
                  if (dockState == 0)

Asked by: First Name493 | Posted: 24-01-2022

Answer 1

Intent.EXTRA_DOCK_STATE only exists in API level 5 and above, so will only work on Android 2.0 devices (or above).

Even although you're wrapping the call in an API level check, the code will fail when you run it on an Android 1.6 runtime, hence the VerifyError.

The solution would be to replace the call to Intent.EXTRA_DOCK_STATE with its constant value: android.intent.extra.DOCK_STATE.

As a general rule, it's a good idea to tick the "Filter by API level" checkbox when browsing the API documentation, and set it to 4 in your case. That way, any classes, methods or constants not available to Android 1.6 will be greyed-out.

Answered by: Carina549 | Posted: 25-02-2022

Answer 2

I had a similar problem, but with bitmap scaling between 1.5 and 1.6. Ended up using something similar to the solution presented in this blog post to make a utility class that switches the code path depending on the API number.

One thing to note in that example since it supports 1.5 it uses android.os.Build.VERSION.SDK which is deprecated, but according to a Dianne Hackborn (Google engineer) it will not be removed in future SDK releases. If you only support 1.6 and above you can use android.os.Build.VERSION.SDK_INT, which is not deprecated.

Also, since you're targeting 1.6, if you aren't that dependent on that version of the framework you might want to look at supporting 1.5 as well, at the time of this writing 1.5 is 31% of Android devices accessing the Android Market.

Answered by: Adrian823 | Posted: 25-02-2022

Answer 3

Since it's an error rather than an exception, it won't extend Exception. Rather, it will extend Throwable, so you have to catch that:

try {


} catch ( Throwable e ) {

Answered by: Justin654 | Posted: 25-02-2022

Answer 4

To catch the error you can do something like this.

try {

  // write your code here

    } catch (VerifyError e) {
        // TODO: handle exception

Answered by: Nicole252 | Posted: 25-02-2022

Similar questions

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android