Preventing verification errors

by Retired on ‎02-16-2010 10:53 AM - edited on ‎06-29-2011 11:26 AM by Retired (7,536 Views)



This article applies to the following:

  • BlackBerry® smartphones based on Java® technology




When developing Java applications for the BlackBerry smartphone, you may encounter any of the following verification errors or errors similar to the following:

  • Verification Error 3141
  • Module 'MyMIDlet' has verification error (<###>) at offset <###>.
  • Error starting MyMIDlet: Module 'MyMIDlet' has verification error (<####>) at offset <###>."

These errors often occur when creating MIDlets. They are inherently hard to debug because the same error message can apply to a number of problems.


The following is a list of possible solutions to prevent or correct verification errors:

  1. If you started by building a Java Archive (JAR) file and then used the RIM Application Program Compiler (RAPC) to create .cod files, make sure you turn obfuscation off when building the JAR file. The RAPC compiler performs its own obfuscation and issues may occur if the code is already obfuscated.
  2. Remove any System.out.* calls. These generally do nothing on the BlackBerry smartphone, but they might cause verification errors.
  3. Remove unused import statements.
  4. Explicitly specify the access for each function or variable. For example, make sure each one is specified as public, private, or protected.
  5. If you are working with a MIDlet, make sure the MIDlet class is declared as public.
  6. Verification errors may occur if the COD file is corrupted or if it was not signed correctly. Make sure that you perform a clean rebuild and that you re-sign your application. Reinstall the application on the BlackBerry smartphone.
  7. Comment out any non-executable code. Verification errors might be related to the size of the main code file and the library files. If you comment out non-executable code, the file sizes change, which may correct the problem.
  8. If you have created any classes that inherit from RIM classes, change the name of any custom methods and members that you created in those classes. This makes sure that you have not named any methods or members of the same name in the internal RIM classes.
  9. If your application is using BlackBerry® Device Software 3.8 or later, verification errors occur when an application that implements the javax.microedition.rms.RecordStore class is compiled using BlackBerry® Java® Development Environment (BlackBerry JDE) earlier than version 4.0. This occurs if the application uses either the addRecordListener or removeRecordListener methods of the RecordStore class. To resolve this issue, recompile the application using BlackBerry JDE 4.0 or later.
  10. There is a problem with how the BlackBerry® Java® Virtual Machine (BlackBerry JVM) handles the referencing of a class directly within the constructor of another class. The following is an example:


    Class1 class1= new Class1(Class2.class.getName());


    To work around this issue, do not make the class call within a constructor as shown in the following example:


    Class1 class1;
    String className = Class2.class.getName();
    Class1 = new Class1(className);


  11. Remove references to a static instance variable from an inner class. For example, the following code example could cause an error:


    public class MyOuterClass {
    static int var;
    class MyInnerClass {
    public void doSomething() {
    var = 7;


    There are a few ways you can remove these references, such as creating get/set methods for var in the outer class or modifying the logic to pull MyInnerClass out of MyOuterClass.

  12. The build procedure normally compiles from the java source file with the javac command, and then runs preverify.exe file and then RAPC. Add the following command line arguments to javac to help avoid issues in earlier versions of the RAPC:


    javac.exe -source 1.3 -target 1.1



  13. Some methods that are very long can cause verification errors. By breaking these methods into helper methods, you can reduce the likelihood of verification errors.
  14. Although not as likely, some very long method definitions (with 10 or more parameters), and some very long constant definitions (long package structure and/or long names) can also cause verification errors.
  15. There is a known issue caused by overflowing the JVM's list of Persistent Classes. It is most often seen after a user has been using their device for a long time and have installed many applications, especially applications which make extensive use of Persistent Classes. Some applications have been found which implement 100 or more, even as high as 500 (classes which implement Persistable or extend PersistentObject). If the same application works on another device with the same software version, or works again if the OS is reinstalled first, and it makes use of some number of Persitent classes then this issue is the cause. Currently the only solution is to reinstall the BlackBerry OS, which clears the Persistent class registry. This registry is not automatically cleared when an application is removed, but a fix for that is planned for a future release. It is recommended that the use of Persistent Classes be minimized following the recommendations made in this article: Best Practices for Persistent Store.
  16. Reduce the number of data members in your class.  In BlackBerry Device Software version 6.0 and lower, if there are more than 256 members in the class hierarchy the application will throw verification errors.  This limit has been increased to 512 if the application has been built using version 7.0 or higher of the BlackBerry Java SDK or BlackBerry JDE and is running on BlackBerry Device Software version 7.0 or higher.