The moose likes Beginning Java and the fly likes NoClassDefFoundError Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic



Joined: Feb 20, 2002
Posts: 2
this is probably going to look like a stupid question. i have a piece of code i got from the "Programmers Guide to Java Certification" textbook. It compiles fine, but doesn't run.
it starts with a line:
package com.acme;
import java.util.*;
now, if i comment out the package statement it runs fine and does what it is supposed to do.
if i leave it as is it gives the error:
Exception in thread "main" java.lang.NoClassDefFoundError: Exercise1 (wrong name: com/acme/Exercise1
The file is named and I run it from the directory c:\javafiles\Chapter2
my Classpath is set to c:\jdk1.3\bin;.;
are there any more environment variables I need to set up or what is the problem here?

Joined: Feb 20, 2002
Posts: 2
thanks guys, found the answer from another thread. i'm quite surprised the people at uni never thought to teach this. guess that's why we are supposed to get off our buts and actually do stuff :-)
happy programming all!
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

when you invoke "java Example1", it looks in the current directory and finds your Example1.class file. But this class file tells java "I'm supposed to be in the package "com/acme/", which it is not.

So.. move your class file to c:\javafiles\Chapter2\com\acme\Exercise1.class
and from c:\javafiles, type: "java com.acme.Example1"

This should work.
I agree. Here's the link:
subject: NoClassDefFoundError
It's not a secret anymore!