Results 1 to 7 of 7
  1. #1
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Bad version number in .class file

    I am getting this exception:
    Java Code:
    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(ClassLoader.java:620)
    	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    	at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    	at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    	at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    	at Startup.gameLoop(Startup.java:31)
    	at Startup.main(Startup.java:17)
    When running this code:
    Java Code:
    import org.lwjgl.input.*;
    import org.lwjgl.opengl.*;
    import org.lwjgl.*;
    import java.util.Random;
    import org.newdawn.slick.opengl.Texture;
    import org.newdawn.slick.opengl.TextureLoader;
    import org.newdawn.slick.util.ResourceLoader;
    
    public class Startup
    {
    	private static Random carl = new Random();
    	
    	public static void main(String[] args)
    	{
    		initDisplay();
    		initGL();
    		gameLoop();
    	}
    	
    	private static void gameLoop()
    	{
    		int i = 0;
    		int j = 0;
    		int oldMinX = 0;
    		int oldMinY = 0;
    		int minX = carl.nextInt(1194);
    		int minY = carl.nextInt(700);
    		Texture tex = null;
    		try
    		{
    			tex = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/image.png"));
    		} catch(Exception e) {
    			e.printStackTrace();
    		}
    		while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE))
    		{
    			GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
    			try
    			{
    				tex.bind();
    			} catch(Exception e) {
    				e.printStackTrace();
    			}
    			
    			GL11.glBegin(GL11.GL_QUADS);
    			{
    				int mouseY = 799 - Mouse.getY();
    				int mouseX = Mouse.getX();
    				try
    				{
    					if(mouseY > minY && mouseY < minY + 100 && mouseX > minX && mouseX < minX + 100)
    					{
    						GL11.glTexCoord2f(0, 0);
    						GL11.glVertex2i(minX, minY);
    						GL11.glTexCoord2f(1, 0);
    						GL11.glVertex2i(minX + 100, minY);
    						GL11.glTexCoord2f(1, 1);
    						GL11.glVertex2i(minX + 100, minY + 100);
    						GL11.glTexCoord2f(0, 1);
    						GL11.glVertex2i(minX, minY + 100);
    						oldMinX = minX;
    						oldMinY = minY;
    						minX = carl.nextInt(1194);
    						minY = carl.nextInt(700);
    						j = 4;
    						i++;
    					}else if(j > 0){
    						j--;
    						GL11.glTexCoord2f(0, 0);
    						GL11.glVertex2i(oldMinX, oldMinY);
    						GL11.glTexCoord2f(1, 0);
    						GL11.glVertex2i(oldMinX + 100, oldMinY);
    						GL11.glTexCoord2f(1, 1);
    						GL11.glVertex2i(oldMinX + 100, oldMinY + 100);
    						GL11.glTexCoord2f(0, 1);
    						GL11.glVertex2i(oldMinX, oldMinY + 100);
    					}
    				} catch(Exception e) {
    					e.printStackTrace();
    				}
    			}
    			GL11.glEnd();
    			
    			Display.setTitle("" + i);
    			Display.update();
    			Display.sync(60);
    		}
    		Display.destroy();
    	}
    	
    	private static void initGL()
    	{
    		GL11.glMatrixMode(GL11.GL_PROJECTION);
    		GL11.glLoadIdentity();
    		GL11.glOrtho(0, 1294, 800, 0, 1, -1);
    		GL11.glMatrixMode(GL11.GL_MODELVIEW);
    		GL11.glEnable(GL11.GL_TEXTURE_2D);
    	}
    	
    	private static void initDisplay()
    	{
    		try
    		{
    			Display.setDisplayMode(new DisplayMode(1294, 800));
    			Display.setTitle("" + 0);
    			Display.create();
    		} catch(LWJGLException e) {
    			e.printStackTrace();
    		}
    	}
    }
    My display opens, it gives me the exception, then it freezes up!
    I have got my java compiler pointers in eclipse set up properly.

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Bad version number in .class file

    Sounds like your compile time and run time java versions are different - ensure that you have your build compatibility set to a version <= your JRE version.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Bad version number in .class file

    That exception usually gives you the version number, which will tell you exactly what version the code was compiled with and what version you are trying to run it on.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default Re: Bad version number in .class file

    And you can find what number corresponds to which Java version here: Java class file - Wikipedia, the free encyclopedia

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: Bad version number in .class file

    It hasnt given me the version number. But when I comment everything that has to do with textures, it compiles and runs fine...

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: Bad version number in .class file

    I suspect then that the opengl stuff was compiled in a later version of Java than you are compiling/running with.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    J-max04 is offline Member
    Join Date
    May 2012
    Posts
    17
    Rep Power
    0

    Default Re: Bad version number in .class file

    It must be slick util.

Similar Threads

  1. Unsupported class version.
    By wdh321 in forum New To Java
    Replies: 8
    Last Post: 10-02-2012, 04:58 PM
  2. Replies: 8
    Last Post: 01-21-2012, 01:14 AM
  3. Shall we skip Unsupported class version error?
    By makpandian in forum New To Java
    Replies: 1
    Last Post: 04-21-2011, 01:11 PM
  4. Set file number on .class file
    By lmsf in forum Advanced Java
    Replies: 3
    Last Post: 03-24-2010, 06:38 AM
  5. Class Version in Serialization
    By Gunas in forum New To Java
    Replies: 5
    Last Post: 02-04-2010, 04:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •