[java] i can compile JAVA, but cant run CLASSes!

Started by
9 comments, last by GekkoCube 18 years, 1 month ago
i can compile java files and it generates class files. but i cant run the classes. c:\java_file_location\java HelloWorld ----------- i reinstalled this JRE last night, jre-1_5_0_06-windows-i586-p-iftw. when i try to run i get this error: 'Exception in thread "main" java.lang.NoClassDefFoundError: HelloJava1' ...and yes, this class does exist.
Advertisement
Quote:Original post by GekkoCube
c:\java_file_location\java HelloWorld
NoClassDefFoundError: HelloJava1'

A class called "HelloJava1" should be in a file called "HelloJava1.class".
A class called "HelloWorld" should be in a file called "HelloWorld.class".

You have seem to have intermixed class name and file name.

Is your class public? And does it have a public static main method?
sorry. the names are all correct.
im using a HelloWorld example that came with a text book on CD.

here's a thought...

if i install the java SDK, in my case jdk1.5.0_06, do i need to install the jre (java runtime), which in my case i have jre1.5.0_06 ?

maybe this has somethign to do with it, although i cant see why this is the problem.

Can you post the entire code via copy and paste into this forum please?

And does this work:

java -cp . HelloWorld

?
Quote:Original post by GekkoCube
if i install the java SDK, in my case jdk1.5.0_06, do i need to install the jre (java runtime), which in my case i have jre1.5.0_06 ?

The SDK includes the JRE. There should be a JRE folder in the SDK folder.

Of course you cannot run .class files built by Java 1.5 with Java 1.4
Fred304

i dont know who you are, but you're a genius.

using java -cp . HelloWorld WORKS!

now allow me to research what the heck this means!
okay, i've no idea.

i know the -cp is for classpath.
but i never had to do this before.

and besides, the class exists in the same folder as the call to java.
so what gives?
also, when i exit the java app, the console gets stuck!
Check to see if the CLASSPATH environment variable is set. If it is, then that could cause the problem. Don't set the CLASSPATH environment variable globally.
"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]
the CLASSPATH is set under systems.

but this only has one path, and it's for quicktime.


maybe i SHOULD set the classpath???

This topic is closed to new replies.

Advertisement