?
Solved

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

Posted on 2007-11-30
6
Medium Priority
?
186 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 750 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

718 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