Console Error...

While trying to run my file on the web, I keep getting the following error messages in my Java console... why is this? The file I am working with is in the reply below...

WIOServerStatusThread finishing (false,true)

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 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.ClassCastException: MinOfThree

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)

Message was edited by:

jamocamac

Message was edited by:

jamocamac

[1800 byte] By [jamocamaca] at [2007-11-27 2:33:13]
# 1

import java.util.Scanner;

public class MinOfThree

{

public static void main (String[] args)

{

int num1, num2, num3, min = 0;

Scanner scan = new Scanner (System.in);

System.out.println ("Enter three integers: ");

num1 = scan.nextInt();

num2 = scan.nextInt();

num3 = scan.nextInt();

if (num1 < num2)

if (num1 < num3)

min = num1;

else

min = num3;

else

if (num2 < num3)

min = num2;

else

min = num3;

System.out.println ("Minimum value: " + min);

}

}

jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 2
Most likey you compiled the file with a higher JDK than you are running with.For instance compiling with JDK1.5 and running with JDK1.4.
knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 3
how do I fix this, I used "javac MinOfThree.java" in WinSCP, is there a better way?
jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 4

yes.....find the actual jdk path...

For instance my JDK path is "C:\jdk1.5.0_03\bin" so I would compile like this:-

C:\jdk1.5.0_03\bin\javac MinOfThree.java

and then run like :-

C:\jdk1.5.0_03\bin\java MinOfThree.java

**NOTE your JDK might be tucked away under program files as this is the default location of JDK installs :-

C:\Program Files\Java\jdk1.5

knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 5
I'm sorry I;m a bit new, could you please explain more, my files are online on a campus network so I only know how to compile through WinSCP, is there a way to do it on my desktop, do u mean run by Start>Run? Also, my version is j2sdk1.4.2_13, does this matter? Thanx in advance...
jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 6

The version doesn't matter. The only rule is don't compile higher than your running JDK version. You can compile lower or same.

Is this just one class or are there many?

You say your files are on Campus, but do you have access to them now? I don't know what WinSCP is (is it some remote tool for compiling)?

Anyway, If you have the java file then you can compile using the command prompt, follow these steps :-

Start -> Run

cd C:\your_folder\

C:\Program Files\Java\j2sdk1.4.2_13\bin\javac YourClass.java

C:\Program Files\Java\j2sdk1.4.2_13\bin\java YourClass.class

Make sure that you are in the same folder as your Class file.

Also you might be able to find the java version on WinSCP by running

java -version

knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 7

Ahhh, the versions are fine, I even tried this on different computers. I just now used putty to javac the file, and it still doesn't appear on the webpage I am posting it on with <applet code="MinOfThree.class"></applet>,, and I still get the errors in the Java console!! This is killing me, help!!!!

jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 8

You must be getting a different error now then because the error above is definately wrong class versions. Post your new errors......Also post completely what you are doing step by step....

Is there more than one class?

Do you have JAR's you need to include on a class path? Or is this just one class?

knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 9
The code you posted works for me....I can compile it and run it and the output looks like this :-Enter three integers: 3 2 1Minimum value: 1So there must be something else that you're doing...post your steps.
knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 10

ok...

1)I compile in putty w/ version 1.5.0_02 by javac MinOfThree.java.

2)I made the html page as follows...

<html>

<head>

<title>

File

</title>

</head>

<body>

<applet code="MinOfThree.class"></applet>

</body>

</html>

3)I try to run it on a webpage but nothing happens, I get "applet MinOfThree notinited" in the browser bottom, and in the java console (Version 1.5.0 (build 1.5.0_04-b05) and then I get...

-

java.lang.ClassCastException: MinOfThree

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-29" 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-MinOfThree.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)

jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 11

Ok.

MinOfThree is not an applet, its a console application.

You can not include this in an html page.

If you want to create an applet do this then your code will be much different, as you'll have to create the user interface.

Go to this site to learn how to create an applet :-

http://java.sun.com/docs/books/tutorial/deployment/applet/index.html

knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 12
Read below...
jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 13

> The version doesn't matter. The only rule is don't

> compile higher than your running JDK version. You

> can compile lower or same.

>

> Is this just one class or are there many?

>

> You say your files are on Campus, but do you have

> access to them now? I don't know what WinSCP is (is

> it some remote tool for compiling)?

>

> Anyway, If you have the java file then you can

> compile using the command prompt, follow these steps

> :-

>

> Start -> Run

>

> cd C:\your_folder\

>

> C:\Program Files\Java\j2sdk1.4.2_13\bin\javac

> YourClass.java

>

> C:\Program Files\Java\j2sdk1.4.2_13\bin\java

> YourClass.class

>

> Make sure that you are in the same folder as your

> Class file.

>

> Also you might be able to find the java version on

> WinSCP by running

> java -version

Hey man, whenever I try to do the "javac name.java" and java name.java" to run it, it shoots something on the screen really fast then closes the command prompt, how can i keep it up to see it run?

jamocamaca at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...
# 14
you need to run it like :-C:\Program Files\Java\j2sdk1.4.2_13\bin\java name.class orC:\Program Files\Java\j2sdk1.4.2_13\bin\java name not C:\Program Files\Java\j2sdk1.4.2_13\bin\java name.java
knightweba at 2007-7-12 2:49:36 > top of Java-index,Java Essentials,Java Programming...