Solved

error

Posted on 2004-09-09
7
224 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 104
java 8 lambda expresssions exception handling 3 88
arguments to jar 5 26
null output 3 24
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

813 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

11 Experts available now in Live!

Get 1:1 Help Now