[java] Working with Files

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

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
m:   print memory usage
o:   trigger logging
q:   hide console
s:   dump system and deployment properties
0-5: set trace level to <n>
----------------------------------------------------

java.lang.UnsupportedClassVersionError: Bad version number in .class file
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
java.lang.NullPointerException
at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
at sun.plugin.AppletViewer.showAppletException(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
java.lang.NullPointerException
at sun.plugin.AppletViewer.showAppletStatus(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
java.lang.UnsupportedClassVersionError: Bad version number in .class file
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.plugin.AppletViewer.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)


[Edited by - alexxzius on July 24, 2007 3:35:15 PM]

Share on other sites
Quote:
 Original post by alexxziusThe 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 on other sites
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

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 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 on other sites
Quote:
 Original post by alexxziusnevermind . . . 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,...);}

Share on other sites
it said here
Image bg = new Image();
Image is static and cant be instantiated . . .

EDIT:
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 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 on other sites
Most games written run at 100% CPU. Do not worry about the CPU usage unless it becomes a problem.

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.

• 10
• 17
• 9
• 14
• 41