• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

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

0
SamsonChung
Asked:
SamsonChung
1 Solution
 
UrosVidojevicCommented:
There is nothing wrong with that code.

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

set classpath=%classpath%;%JAVA_HOME%\bin;.;
0
 
SamsonChungAuthor Commented:
.....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
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
UrosVidojevicCommented:
Try using:

java -cp c:\myfolder omega

assuming that your files are located in c:\myfolder.
This way you can specify where your files are.
0
 
ysnkyCommented:
to run a class you need to add it to classpath, so as UrosVidojevic said, you can run it from an folder.
0
 
SamsonChungAuthor Commented:
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 ??
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now