It turns out that VerifyError as per the Android docs is defined differently and more accurately: "Thrown when the virtual machine notices that an attempt is made to load a class which does not pass the class verification phase. " Makes a lot of sense in my case.
On Mar 16, 9:39 am, Nikhil Agarwal <[email protected]> wrote: > As per javadocs, Verify error is "thrown when the 'verifier' detects > that a class file, though well formed, contains some sort of internal > inconsistency or security problem". > I encountered it once before when I was trying to instantiate > different classes by checking the version of sdk. Even though I > ensured that the right class will be instantiated depending on the > sdk, somehow the vm could see my 'else' part and it sometimes threw > the 'Verify Error'. Probably the fact that I am even trying to > instantiate a class which does not exist for the platform led to this > error. Solved the problem by seeing how the business card sample app > uses reflection. > > In your case, it seems like GeoPoint class is not present on all > devices and so a Verify Error is being thrown (if not verified, an > exception will be thrown later when this class is instantiated). What > you can probably do is that use reflection to instantiate the above > class, and then handle the exception gracefully. Or you can check the > platform version and then instantiate the LocationHelper class (once > again using reflection). > > Check > outhttp://developer.android.com/resources/samples/BusinessCard/src/com/e... > for suggestions on how you can use reflection for platform dependent > stuff. > > On Mar 15, 10:07 pm, Tim <[email protected]> wrote: > > > I developed the gig guide application Alice, but I have run into a > > problem I haven't been able to solve... > > > A bunch of users with Android 1.5 are reporting Force Closes because > > of Verify Errors. > > > I have a LocationHelper class which has GeoPoint in one of its method > > signatures. When I instantiate this class, a VerifyError is thrown. > > The weird thing is seems to be very rarely thrown. I saw it only once > > on my HTC Hero. I am unable to reproduce it, but I know that a lot of > > my 1.5 users get this problem. > > > Problem Class > > > public class LocationHelper implements LocationListener { > > > public static final double RADIUS_KILOMETERS = 6378; > > public static final double RADIUS_MILES = 3963; > > > private static LocationHelper instance; > > private GeoPoint myGeoPoint; > > > public static LocationHelper getInstance(Context context) { > > if (instance == null) { > > instance = new LocationHelper(context); > > } > > return instance; > > } > > > public static double calculationByDistance(GeoPoint StartP, GeoPoint > > EndP, double radius) { > > double lat1 = StartP.getLatitudeE6() / 1E6; > > double lat2 = EndP.getLatitudeE6() / 1E6; > > double lon1 = StartP.getLongitudeE6() / 1E6; > > double lon2 = EndP.getLongitudeE6() / 1E6; > > double dLat = Math.toRadians(lat2 - lat1); > > double dLon = Math.toRadians(lon2 - lon1); > > double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + > > Math.cos(Math.toRadians(lat1)) > > * Math.cos(Math.toRadians(lat2)) * > > Math.sin(dLon / 2) * > > Math.sin(dLon / 2); > > double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); > > return radius * c; > > } > > > ... > > > } > > > The class which calls the LocationHelper uses this code, and this is > > where the VerifyError is thrown: > > > LocationHelper helper = LocationHelper.getInstance(context); > > > Extract from the manifest file: > > > <uses-library > > android:name="com.google.android.maps" /> > > > <uses-sdk > > android:minSdkVersion="3" > > android:targetSdkVersion="4" /> > > > Stack trace > > > 03-12 04:28:09.295 I/ActivityManager( 67): Displayed activity > > com.android.vending/.AssetInfoActivity: 405 ms > > 03-12 04:28:25.845 I/ActivityManager( 67): Start proc com.citc.alice > > for broadcast com.citc.alice/.EventAlarmReceiver: pid=9508 uid=10051 > > gids={3003} > > 03-12 04:28:27.135 W/dalvikvm( 9508): VFY: unable to find class > > referenced in signature (Lcom/google/android/maps/GeoPoint;) > > 03-12 04:28:27.135 W/dalvikvm( 9508): VFY: unable to find class > > referenced in signature (Lcom/google/android/maps/GeoPoint;) > > 03-12 04:28:27.165 W/dalvikvm( 9508): VFY: unable to find class > > referenced in signature (Lcom/google/android/maps/GeoPoint;) > > 03-12 04:28:27.165 E/dalvikvm( 9508): Could not find method > > com.google.android.maps.GeoPoint.getLatitudeE6, referenced from method > > com.citc.alice.util.LocationHelper.calculationByDistance > > 03-12 04:28:27.165 W/dalvikvm( 9508): VFY: unable to resolve virtual > > method 1259: Lcom/google/android/maps/GeoPoint;.getLatitudeE6 ()I > > 03-12 04:28:27.165 W/dalvikvm( 9508): VFY: rejecting opcode 0x6e at > > 0x0000 > > 03-12 04:28:27.165 W/dalvikvm( 9508): VFY: rejected Lcom/citc/alice/ > > util/LocationHelper;.calculationByDistance (Lcom/google/android/maps/ > > GeoPoint;Lcom/google/android/maps/GeoPoint;D)D > > 03-12 04:28:27.165 W/dalvikvm( 9508): Verifier rejected class Lcom/ > > citc/alice/util/LocationHelper; > > 03-12 04:28:27.175 D/AndroidRuntime( 9508): Shutting down VM > > 03-12 04:28:27.175 W/dalvikvm( 9508): threadid=3: thread exiting with > > uncaught exception (group=0x4000fe70) > > 03-12 04:28:27.175 E/AndroidRuntime( 9508): Uncaught handler: thread > > main exiting due to uncaught exception > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): java.lang.VerifyError: > > com.citc.alice.util.LocationHelper > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > com.citc.alice.AliceApplication.onCreate(AliceApplication.java:20) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java: > > 1048) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.app.ActivityThread.handleBindApplication(ActivityThread.java: > > 3622) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.app.ActivityThread.access$2500(ActivityThread.java:112) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.app.ActivityThread$H.handleMessage(ActivityThread.java:1729) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.os.Handler.dispatchMessage(Handler.java:99) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.os.Looper.loop(Looper.java:123) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > android.app.ActivityThread.main(ActivityThread.java:3948) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > java.lang.reflect.Method.invokeNative(Native Method) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > java.lang.reflect.Method.invoke(Method.java:521) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > com.android.internal.os.ZygoteInit > > $MethodAndArgsCaller.run(ZygoteInit.java:782) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540) > > 03-12 04:28:27.225 E/AndroidRuntime( 9508): at > > dalvik.system.NativeStart.main(Native Method) > > > I thought it might be just not compatible with API 3 (1.5) but then > > why does it work most of the time and then sometimes complain about > > the class? > > > If someone can help I would really appreciate it! This one has really > > got me stumped.. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

