Can not catch java.lang.VerifyError

微信扫一扫,分享到朋友圈

Can not 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?

Thanks!

private BroadcastReceiver mUndockedReceiver = new BroadcastReceiver()
{
      @Override
      public void onReceive(Context context, Intent intent)
      {
          //FROM ECLAIR FORWARD, BEFORE DONUT THIS INTENT WAS NOT IMPLEMENTED
          if (Build.VERSION.SDK_INT >= 5)
          {
              if (!isInitialStickyBroadcast()) {
                  int dockState = intent.getExtras().getInt("android.intent.extra.DOCK_STATE", 1);
                  if (dockState == 0)
                  {
                      finish();
                  }
              }
          }
      }
};


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.

Facebook rolls out its downvote button to more users

上一篇

Towards More Automated Printers

下一篇

你也可能喜欢

Can not catch java.lang.VerifyError

长按储存图像,分享给朋友