Jump to content
  • Advertisement
Sign in to follow this  
alexxzius

[java] Working with Files

This topic is 4117 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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 image
gI.draw(...);

//draw bg to screen
g.drawImage(bg,...);
}


Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites


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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!