Solved

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

Posted on 2007-11-30
6
180 Views
Last Modified: 2010-03-30
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
Comment
Question by:SamsonChung
6 Comments
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20384440
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
 
LVL 17

Expert Comment

by:contactkarthi
ID: 20384868
try setting classpath as

set classpath=%classpath%;%JAVA_HOME%\bin;.;
0
 
LVL 6

Author Comment

by:SamsonChung
ID: 20385025
.....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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 250 total points
ID: 20385135
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
 
LVL 9

Expert Comment

by:ysnky
ID: 20385342
to run a class you need to add it to classpath, so as UrosVidojevic said, you can run it from an folder.
0
 
LVL 6

Author Comment

by:SamsonChung
ID: 20397599
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now