Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

error

Posted on 2004-09-09
7
Medium Priority
?
231 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 75 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

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 had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

618 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