[java] Working with Files

Started by
42 comments, last by alexxzius 16 years, 8 months ago
ok, java claims that it can run on anything that has a screen (phones, calculators, tv's, wristwatches etc) but I tried to run my game on several computers and every time it gave me bad version exceptions. The computers have the same JRE and JVM (Windows). So what i gotta do is to get JDK, compile every java file, then it works fine. Is that how it works or am i missing something?

Java Plug-in 1.5.0_06
Using JRE version 1.5.0_06 Java HotSpot(TM) Client VM
User home directory = C:\Documents and Settings\Computer


----------------------------------------------------
c:   clear console window
f:   finalize objects on finalization queue
g:   garbage collect
h:   display this help message
l:   dump classloader list
m:   print memory usage
o:   trigger logging
p:   reload proxy configuration
q:   hide console
r:   reload policy configuration
s:   dump system and deployment properties
t:   dump thread list
v:   dump thread stack
x:   clear classloader cache
0-5: set trace level to <n>
----------------------------------------------------

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 sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
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 sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-9" java.lang.NullPointerException
	at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
	at sun.plugin.AppletViewer.showAppletException(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
	at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
	at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception in thread "thread applet-tennis1.class" java.lang.NullPointerException
	at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
	at sun.plugin.AppletViewer.showAppletException(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
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 sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Exception in thread "Thread-13" java.lang.NullPointerException
	at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
	at sun.plugin.AppletViewer.showAppletException(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
java.lang.NullPointerException
	at sun.plugin.util.GrayBoxPainter.showLoadingError(Unknown Source)
	at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
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 sun.applet.AppletClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.applet.AppletClassLoader.loadCode(Unknown Source)
	at sun.applet.AppletPanel.createApplet(Unknown Source)
	at sun.plugin.AppletViewer.createApplet(Unknown Source)
	at sun.applet.AppletPanel.runLoader(Unknown Source)
	at sun.applet.AppletPanel.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

[Edited by - alexxzius on July 24, 2007 3:35:15 PM]
Advertisement
Quote:Original post by alexxzius
The computers have the same JRE and JVM (Windows).


Are you sure? That error indicates that you are compiling with a newer JVM than what is on the machine that is trying to run your program. Are you using JDK v1.6 to compile with?
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]
if you are sure that they're all using 1.5, maybe you're compiling on 1.5.0_09 while they are running 1.5.0_06
------------------http://openwar.bartvanheukelom.nl - Open Source RTS Engine, new people welcome
Java apps only throw bad version exceptions if the requisite version of Java is not installed. Go to java.sun.com and download the latest JRE.

I've been getting that error a lot because a new version of Java was released recently, and people have versions that are 1, sometimes 2, editions old.
nevermind . . . It was just me saying things cause java is so difficult.

An unrelated qiuestion:
Can i draw stuff on an empty image and then draw that image on the screen? (please show code cause im stupid). ;0
Quote:Original post by alexxzius
nevermind . . . It was just me saying things cause java is so difficult.

An unrelated qiuestion:
Can i draw stuff on an empty image and then draw that image on the screen? (please show code cause im stupid). ;0


paint(Graphics g){Image bg = new Image();Graphics gI = bg.getGraphics()//Draw stuff to bg imagegI.draw(...);//draw bg to screeng.drawImage(bg,...);}
it said here
Image bg = new Image();
Image is static and cant be instantiated . . .

EDIT:
ok, instead of
Image bg = new Image();

i put
Image bg=createImage(room_width,room_height);

It is working now but not with the desired results. What i wanted to do is to cut down on my CPU. Originally i had a double for loop that drew 192 tiles (16 x 12) to Graphics g every step (30 times a second). My idea was to draw the tiles on an image and then draw it on the screen (which happens on average every 5 seconds). But my CPU went higher when doing it. Is it normal or am i doing something wrong?
That's because you're creating an image every time you draw to the screen.

Create the image outside of the paint method, like in the constructor. If the component is resizable, instead check in the paint method to make sure the image is null or a different size than the component before creating a new one.

You can also use java.awt.image.BufferedImage.
Most games written run at 100% CPU. Do not worry about the CPU usage unless it becomes a problem.
"None of us learn in a vacuum; we all stand on the shoulders of giants such as Wirth and Knuth and thousands of others. Lend your shoulders to building the future!" - Michael Abrash[JavaGaming.org][The Java Tutorial][Slick][LWJGL][LWJGL Tutorials for NeHe][LWJGL Wiki][jMonkey Engine]


And to add a bit of information still in addition to the previous posts, it is not possible to run the same Java applications on every Java runtime environment. For instance, Jave Mobile Edition is different than that of the desktop version. You have to modify your code somewhat or the thing you are trying to do is impossile all together. Also different handsets have different features, different bugs and different amount of resources.

I have written .NET, .NET Compact Framework, Symbian (Series 60), Palm OS and also J2ME applications and my experience is that .NET and .NET CF are very close to each other. In CF there are more static methods and thread handling if a bit different, but otherwise teh APIs are consistent. In Windows CE phones there aren't all the APIs or one have to resort to platform invoke (P/Invoke) to make Win32 calls, but otherwise quite similar.

---Sudet ulvovat - karavaani kulkee

This topic is closed to new replies.

Advertisement