Link to home
Start Free TrialLog in
Avatar of SamsonChung
SamsonChungFlag for Canada

asked on

What am I forgetting in this code? It must be something simple!!

Ok, I did the following on a Windows Xp machine running Java 1.5

%JAVA_HOME%\bin\javac omega.java
%JAVA_HOME%\bin\java omega
JVM returned
Exception in thread "main" java.lang.NoClassDefFoundError: omega

My directory consists of two files
omega.java
omega.class

What am I doing wrong?

My code is attached.
public class omega{
	public omega(){
		System.out.println("this is a test");
	}
	public static void main(String[] args){
		new omega();
	}
}

Open in new window

Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

There is nothing wrong with that code.

Just go to that folder (containing .class and .java file), run command prompt and enter:
java omega
Avatar of contactkarthi
try setting classpath as

set classpath=%classpath%;%JAVA_HOME%\bin;.;
Avatar of SamsonChung

ASKER

.....That's what I thought! There is nothing wrong with that code!!

The only question remains is why doesn't it work?

Thanks guys, but ur suggestions were already attempted. (its not like I am haven exhausted my own mind before posting on here...)

Uros, that's how I got that damn Exception error!
contactkarthi, Classpath is already set, that's how I get %JAVA_HOME%\bin javac to work in the first place....

I can bet you 1000 rupies that when I put that java file and that class file on a Unix/Linux system, it'd run smoothly without problem.

To top that, when I ran that code in in Eclipse ore NetBeans, it works!

@.@ <- me, dizzy
ASKER CERTIFIED SOLUTION
Avatar of UrosVidojevic
UrosVidojevic
Flag of Serbia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
to run a class you need to add it to classpath, so as UrosVidojevic said, you can run it from an folder.
Ok, I've tried it UrosVidojevic's command does work.

But then the question arose, Why doesn't this happen on my linux systems??

Also, I remember doing just simple java classname in cmd back when using 1.4.2_*

Is that one of the things that were changed from 1.4.2 to 1.5.0 ??