Cannot catch java.lang.VerifyError

I get this error: "Sewage handler: main thread exiting due to java.lang.VerifyError uncaught exception"

This only happens on 1.6. Android 2.0 and above do not have any problems, but this is important.

I cannot catch the error / exception (VerifyError), and I know that this is caused by calling isInitialStickyBroadcast (), which is not available in SDK 4, so it was completed in SDK check. I just need this BroadcastReceiver to work on 2.0+, and not for a break of 1.6, this is an application on the market, the UNDOCK function is needed for users with 2.0+, but obviously not in 1.6, but the number of users is still at 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(); } } } } }; 
+4
source share
4 answers

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

Even though you end the call in checking the API level, the code will fail when you run it while Android 1.6 is running, hence VerifyError .

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


As a rule, it is recommended to use the "Filter by API" checkbox when viewing the API documentation and set it to 4. In this way, any classes, methods or constants that are not available for Android 1.6 will be grayed out.

+4
source

I had a similar problem, but with raster image 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 that should be noted in this example, since it supports 1.5, uses android.os.Build.VERSION.SDK , which is deprecated, but according to Dianne Hackborn (Google engineer), it will not be removed in future versions of the SDK. If you only support 1.6 and above, you can use android.os.Build.VERSION.SDK_INT , which is not deprecated.

In addition, since you have targeted at 1.6, if you are not dependent on this version of the framework, you can look at support 1.5, and at the time of writing 1.5 this is 31% of Android devices , access to the Android Market.

+2
source

Since this is more a mistake than an exception, it will not be extended by Exception . Rather, it will expand Throwable , so you need to catch this:

 try { .... } catch ( Throwable e ) { } 
0
source

To catch a bug, you can do something like this.

 try { // write your code here } catch (VerifyError e) { // TODO: handle exception } 
0
source

All Articles