Solved

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

Posted on 2007-11-30
6
179 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
Comment Utility
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
Comment Utility
try setting classpath as

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

Author Comment

by:SamsonChung
Comment Utility
.....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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
powerN  challenge 3 46
changeXy challenge 13 56
countHi2 challenge 7 43
Non-recursive backtracking, using a stack 1 45
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

763 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

5 Experts available now in Live!

Get 1:1 Help Now