Select to view content in your preferred language

Error: Bad version number in .class file (Java)

731
2
08-11-2011 06:07 AM
Bende_Groot
New Contributor
I am trying to create a simple ArcObjects console app however when trying to initialize the ArcGIS licenses I always get the following error.

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file

The error is encountered on the following line of code
ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);

I am using ArcObjects 9.3.1 and JRE 1.5.0 Update 10

I can successfully run the Scenario.Utility Object project located in the ArcGIS\java\samples\engine\ folder without error.  This uses the exact same method to initialize the arcGIS license. I can also run my custom code if I put the class within the sample project.  I have gone through the differences within the two projects and cannot find any differences between the Build Path or Complier.

Any help would be appreciated.

-Ben de Groot

Below is a full code of the .java file

import java.io.IOException;
import java.net.UnknownHostException;

import com.esri.arcgis.datasourcesGDB.FileGDBWorkspaceFactory;
import com.esri.arcgis.geodatabase.IWorkspaceFactory;
import com.esri.arcgis.geodatabase.Workspace;
import com.esri.arcgis.interop.AutomationException;
import com.esri.arcgis.system.EngineInitializer;

public class testCreateMap {
    
    
 public static void main(String[] args) {
  System.out.println("Start Create Map"); // Display the string.
  IWorkspaceFactory workspaceFactory = null;
  Workspace workspace = null;
  
  try {

            //Step 1: Initialize the Java Componet Object Model (COM) Interop.
            EngineInitializer.initializeEngine();

            //Step 2: Initialize an ArcGIS license.
            //AoInitialize aoInit = new AoInitialize();
            //initializeArcGISLicenses(aoInit);
            initializeArcGISLicenses();
            
   //BD TODO the feature set will need to be passed in 
   workspaceFactory = new FileGDBWorkspaceFactory(); 
   
   workspace = (Workspace) workspaceFactory.openFromFile("C:\\arcgisserver\\arcgisinput\\data\\NAISMA_scratch.gdb", 0);

   
   System.out.println("End Create Map"); // Display the string.
   
  }  catch (UnknownHostException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (AutomationException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }

 }
 
 static void initializeArcGISLicenses() {
  try {
   com.esri.arcgis.system.AoInitialize ao = new com.esri.arcgis.system.AoInitialize();
   if (ao.isProductCodeAvailable(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine) == com.esri.arcgis.system.esriLicenseStatus.esriLicenseAvailable)
    ao.initialize(com.esri.arcgis.system.esriLicenseProductCode.esriLicenseProductCodeEngine);
  } catch (Exception e) {
   e.printStackTrace();
  }
 }

}
0 Kudos
2 Replies
EricBader
Honored Contributor
This typically happens when you are compiling your code to be compliant with one version of Java, say, compiling for Java 1.6, but then your Java Runtime version tries to use your compiled class files in Java 1.5, for example. Do you see what I mean?

Are you using Eclipse? If so, you can make sure you are compiling your source code to the correct level by going to "Project Properties-->Java Compiler", then view your compliance settings. If you are using Java 1.5 at runtime, make sure your compliance settings in your IDE are set for 1.5.

Recompile, then redeploy. I hope this helps.
0 Kudos
Bende_Groot
New Contributor
Thanks for your help.

I am using eclipse. And checked the compliance level for the project and they match the run time.

Again I am using JRE 1.5.0_10 for the build path and compliance is set to 5.0
(My understanding is 1.5.0 is the same as 5.0)

Again there are some projects, which have started out of example projects, that work on the exact code that do not get this error.

Below is the full stack of the error message. 

Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad version number in .class file
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at com.esri.arcgis.interop.extn.RegTool.a(Unknown Source)
at com.esri.arcgis.interop.extn.RegTool.register(Unknown Source)
at com.esri.arcgis.interop.NativeObjRef.nativeVtblInvoke(Native Method)
at com.esri.arcgis.interop.NativeObjRef.a(Unknown Source)
at com.esri.arcgis.interop.Dispatch.vtblInvoke(Unknown Source)
at com.esri.arcgis.system.IAoInitializeProxy.initialize(Unknown Source)
at com.esri.arcgis.system.AoInitialize.initialize(Unknown Source)
at testCreateMap.initializeArcGISLicenses(testCreateMap.java:53)
at testCreateMap.main(testCreateMap.java:26)
0 Kudos