Solved

error

Posted on 2004-09-09
7
222 Views
Last Modified: 2010-03-31
im in a fix,m i got this problem with java..
Whenver i try to run a progrm, i get an error saying "NoClassDefFoundError", although the program is compiled well!!!

0
Comment
Question by:IOException
7 Comments
 
LVL 7

Expert Comment

by:bvanderveen
ID: 12020668
You need to set the classpath to reference the parent directory.

to run:  java -cp . MyClass  

The above sets the classpath to the current directory.  

If that doesn't work, tell us what class you are trying to run, what package it is in (if any), directory structure, and what dir you are running from.
0
 
LVL 1

Author Comment

by:IOException
ID: 12020760
well i tried everything you guys suggested, but of no use

my java folder is in D:/java
bin is in D:/java/bin

all my programs which used to compile earlier no longer work!
0
 
LVL 7

Accepted Solution

by:
bvanderveen earned 25 total points
ID: 12020885
If you can't compile, your PATH probably needs to be set.

c:/>set PATH=%PATH%;d:/java/bin

You can permanently set this by going to (Win2K) Start>Settings>System, Advanced tab, Environmental Variables
What do you get if you type in
    java - version

If your system can't find this, it is a path problem.  You can either set the path, or make it explicit:
   d:/java/bin/javac MyClass.java         //to compile
   d:/java/bin/java -cp . MyClass          //to run

0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 16

Expert Comment

by:gnoon
ID: 12023624
>Whenver i try to run a progrm, i get an error saying "NoClassDefFoundError", although the program is compiled well!!!

Except the classpath was configured correctly,

- did the java code is planed to be in a package (the first code in java file is 'package <package>;') ?
- did the java class be in the right folder (be compiled with -d option)?
- did you specify the right class name for java program? ..... i.e. java <package>.MyClass
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12024237
I wish I could see your computer.
If you just "go" to the folder with the .class file and say     java classfile (name it yourself correctly)
then it should work, without any addition.

So, if the classfile is named                     Program.class
I expect the class has the same name,
do                                                        java Program

does that work?

;JOOP!
0
 
LVL 16

Expert Comment

by:gnoon
ID: 12024686
>does that work?
Not at all.

Assume the java code look like this:

// Program.java

package my; //<----------- this means that this class must be placed in folder 'my' at runtime.

public class Program
{
    public static void main(String[] args)
    {
        System.out.println("Hello World!");
    }
}

and placed in directory d:\java.
If you compiled it with following command,

D:\java>javac Program.java -d .

then you'll get a class file at d:\java\my\Program.class ..... this is the RIGHT path.

If you compiled it with following command,

D:\java>javac Program.java

then you'll get a class file at d:\java\Program.class ..... this is the WRONG path and need moving to the right path as above.

When you try to run it with the following command (assume the path, d:\java, is already in CLASSPATH)

D:\java>java my.Program

then the java program will be executed properly, but you'll got NoClassDefFoundError if you run it with the following commands:
    - d:\java>java Program
    - d:\java\my>java Program
0
 
LVL 16

Expert Comment

by:gnoon
ID: 12024713
IOException, can you please post the full error stack you got?
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

758 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

17 Experts available now in Live!

Get 1:1 Help Now