Solved

error

Posted on 2004-09-09
7
225 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to get all the API from website? 11 104
eclipse shortcuts 9 63
even odd program using while loop 3 60
Eclipse for Java EE development 2 28
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
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…

839 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