6

Hello I get this error every time I'm trying to open an activity

java.lang.VerifyError: com.karriapps.smartsiddur.Saharit
at java.lang.Class.newInstanceImpl(Native Method)
at java.lang.Class.newInstance(Class.java:1429)
at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
at android.app.ActivityThread.access$2300(ActivityThread.java:125)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

Can someone direct me to a solution or a way to check where the problem is coming from thanks

orelzion
  • 2,452
  • 4
  • 30
  • 46

4 Answers4

7

A VerifyError means your compiled bytecode is referring to something that Android cannot find. In this case, it would appear that you have a reference to a com.karriapps.smartsiddur.Saharit class that Android cannot find.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • But it works fine on my device (Android 2.3.5) it is only showing that message in Android 2.1 and 2.2 – orelzion Oct 03 '11 at 22:23
  • 1
    @oreizion: Then probably you are referring to some class or method in Android from `com.karriapps.smartsiddur.Saharit` that does not exist on API Level 7 or 8, but only on API Level 9+. You might temporarily drop your build target down to API Level 7 to see if that tells you where you are going wrong. – CommonsWare Oct 03 '11 at 22:41
3

As CommonsWare mentioned, a VerifyError means that you're trying to reference a class that Dalvik isn't able to load.

It's possible that this class is missing.

It's also possible that you're trying to use framework methods for an API level greater than what's present on the device, and therefore the class is being rejected as invalid.

Try setting your compiler's build level to API Level 7, which corresponds to Android 2.1. (Don't forget to set your AndroidManfest.xml's targetSdkVersion to "7" as well.) This will cause any framework calls that don't exist to raise a compiler error.

You also might want to look at the lines above/below the stack trace you received to see if there's any additional information from the verifier indicating why verification failed.

Trevor Johns
  • 15,682
  • 3
  • 55
  • 54
1

I found an interesting case that has evidence in runtime. I use:

<uses-sdk
   android:minSdkVersion="9"
   android:targetSdkVersion="18" />

So some of new Android 4 capabilities are not implenented in Android 2.3 like this one:

imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);

Ok I can manage it so runtime will not execute it, simply:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
   setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

This works well but what about Exception handling?

} catch (NetworkOnMainThreadException nomte) {
   // log this exception
} catch (SocketTimeoutException socketTimeoutException) {
   // log this exception
}

NetworkOnMainThreadException is not implemented in Android 2.3 so when the class is loaded the exception java.lang.VerifyError occurs.

Seraphim's
  • 12,559
  • 20
  • 88
  • 129
0

I ran across this problem today and as CommonsWare mentioned, the issue is that my compiled bytecode was referring to something that no longer existed. But what should you do about it?

Since I'm using Eclipse SDK the simple solution for me was to perform an Eclipse's Project → Clean to remove the pre-compiled byte code in my project that was causing the problem. The Project clean put simply allowed eclipse to perform a full fresh rebuild of my project after the clean.

DK2
  • 502
  • 7
  • 5