I am trying to just compile a very back program and it compiles but when I run it I get errors:

Java version = java version "1.5.0_09"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_09-b03)
Java HotSpot(TM) Server VM (build 1.5.0_09-b03, mixed mode)

Program HelloJava.java

public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello, Java!");

or import javax.swing.*;

public class HelloJava
public static void main( String[] args )
JFrame frame = new JFrame( "Hello, Java!" );
JLabel label = new JLabel("Hello, Java!", JLabel.CENTER );
frame.add ( label );
frame.setSize( 300, 300 );
frame.setVisible( true );

After I compile and run either program above which appear to be correct (no compile errors) I get the following:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloJava

I used to be able to do this sort of program (v1.4?) and did not have any problems.

Can anyone assist or suggest what I am doing wrong?


10 Years
Discussion Span
Last Post by haxpor

Hmmm, strange problem,
If you are on windows, can u try first running the command set CLASSPATH= , and then trying to run the program in the same console after it.

Oh yes and please remember to wrap code in code tags


Set the CLASSPATH Variable to include also './'

This tell java to also regard the current directory to be our path of containing classes too.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.