Solved

error

Posted on 2004-09-09
7
227 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
[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
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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Maven Project: Hibernate Dependencies Conflict 10 85
maven module vs maven project 3 108
ejb mdb examples 1 36
Java program running SQL query 5 60
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 …
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…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.
Suggested Courses

738 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