Solved

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

Posted on 2007-11-30
6
185 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…

617 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