Home » Android » android – VFY: unable to find class referenced in signature

android – VFY: unable to find class referenced in signature

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have a simple android application which uses a modbus library (“jamod”) on its build path. It crashes immediately as i run it. I have basically the same problem in this question: Getting "Caused by: java.lang.VerifyError:"

But i cannot really fix the problem. My application was working fine before, now no matter what i do it doesn’t seem to work.

Below is logcat output. Thanks in advance.

08-09 14:36:47.753: W/dalvikvm(396): VFY: unable to find class referenced in signature (Lnet/wimpi/modbus/net/TCPMasterConnection;)
08-09 14:36:47.823: W/dalvikvm(396): VFY: unable to resolve exception class 510 (Lnet/wimpi/modbus/ModbusIOException;)
08-09 14:36:47.823: W/dalvikvm(396): VFY: unable to find exception handler at addr 0x18
08-09 14:36:47.854: W/dalvikvm(396): VFY:  rejected Lcom/example/xmlparsertest/JavaModBusTcpDriver;.<init> (Ljava/lang/String;I)V
08-09 14:36:47.854: W/dalvikvm(396): VFY:  rejecting opcode 0x0d at 0x0018
08-09 14:36:47.854: W/dalvikvm(396): VFY:  rejected Lcom/example/xmlparsertest/JavaModBusTcpDriver;.<init> (Ljava/lang/String;I)V
08-09 14:36:47.854: W/dalvikvm(396): Verifier rejected class Lcom/example/xmlparsertest/JavaModBusTcpDriver;
08-09 14:36:47.854: D/AndroidRuntime(396): Shutting down VM
08-09 14:36:47.854: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
08-09 14:36:47.873: E/AndroidRuntime(396): FATAL EXCEPTION: main
08-09 14:36:47.873: E/AndroidRuntime(396): java.lang.VerifyError: com.example.xmlparsertest.JavaModBusTcpDriver
08-09 14:36:47.873: E/AndroidRuntime(396):  at com.example.xmlparsertest.MainActivity.<init>(MainActivity.java:13)
08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.Class.newInstanceImpl(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.Class.newInstance(Class.java:1429)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.os.Looper.loop(Looper.java:123)
08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.main(ActivityThread.java:4627)
08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.reflect.Method.invokeNative(Native Method)
08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.reflect.Method.invoke(Method.java:521)
08-09 14:36:47.873: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-09 14:36:47.873: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-09 14:36:47.873: E/AndroidRuntime(396):  at dalvik.system.NativeStart.main(Native Method)
How to&Answers:

Did you put the jamod jar file in the “libs” directory in Eclipse? If not it won’t be bundled into your application even if it is on the path during compilation. This is a fairly new change.

Answer:

One thing to double check you are doing is that the checkbox is ticked for the jar files in the “Order and Export” tab in the Build path window. That will include the library in the built APK.

Answer:

I had a similar VFY, link and class def not found errors even though all of my libraries were in “LIB” folder and had added them in build path as well and ECLIPSE could find them easily in compile time, but when they were deployed on a real device, it gave problems.
Solution: Make sure your library files are placed in “libs” folder and not in “lib” or “library” in the ECLIPSE project.

Answer:

This error (java.lang.VerifyError) comes when there are incompatible resources like interfaces/class/libs files, improper inheritances/encapsulation of static/instance level identifiers as variables/methods/arguments/class/files.

This issue is coming by simply violation of OOP design principles in the code. So the code rejected by verification process of jvm and throws verification error on runtime. If you closely look at the Error stacktrace, Instance of class-A(com.example.xmlparsertest.MainActivity) is being created by jvm stack [java.lang.Class.newInstanceImpl(Native Method)… java.lang.Class.newInstance…]. This class is referring or being reffered by other classes with violation of design principles which is causing the class to fail to get instantiated.

    08-09 14:36:47.854: W/dalvikvm(396): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
    08-09 14:36:47.873: E/AndroidRuntime(396): FATAL EXCEPTION: main
    08-09 14:36:47.873: E/AndroidRuntime(396): java.lang.VerifyError: com.example.xmlparsertest.JavaModBusTcpDriver
    08-09 14:36:47.873: E/AndroidRuntime(396):  at com.example.xmlparsertest.MainActivity.<init>(MainActivity.java:13)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.Class.newInstanceImpl(Native Method)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.Class.newInstance(Class.java:1429)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.os.Handler.dispatchMessage(Handler.java:99)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.os.Looper.loop(Looper.java:123)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at android.app.ActivityThread.main(ActivityThread.java:4627)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.reflect.Method.invokeNative(Native Method)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at java.lang.reflect.Method.invoke(Method.java:521)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    08-09 14:36:47.873: E/AndroidRuntime(396):  at dalvik.system.NativeStart.main(Native Method)

These warnings cannot be ignored because these warnings are causing the FATAL EXCEPTIONS. Dalvikvm Engineers have implemented the OOP principles as Sun Engineers Done. There are various blogs/forum where people says to ignore these warning. So do not ignore these warning and correct them especially for medical/banking/security field applications or that warning is causing to break the Application.

Do recheck your implemented OOP design principles (e.g. inheritances/encapsulation/polymorphism etc.) in the code. I was being asked to check and eliminate such errors on a big multi-module android application and i found many design violations.

First trigger to solve such issues make public/non-final everything related to class which is getting into FATAL ERROR. Once you solved, then implement your design principles one-by-one and you will get an error free appplication.

Thanks,
Vinod Bherwal (Android Architect).