wood burning stoves
The moose likes Beginning Java and the fly likes The NoClassDefFound error, I'm stuck Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The NoClassDefFound error, I Watch "The NoClassDefFound error, I New topic

The NoClassDefFound error, I'm stuck

Giles Buist

Joined: Sep 27, 2005
Posts: 8
Hi all,

I'm very new to Java or any programming for that matter. So currently trying to teach myslef using a book called Java First Contact.

Have got to the chapter3 exercises. Tryin to build a program that uses a class file that came on a disk with the book. I've loaded the files on the disk into the directory of the file I'm building. Following the books instructions I've written this staement at the top of my file:

import classes.bytecode.*;

Which I believe tells the compiler to look in a subdirectory called classes then one called bytecodes. In the bytecodes directory is the class file i want to use.

I've also set the classpath to look in this directory by writting

C:\ set classpath=JavaFC;classes;bytecode

However when trying to compile my file I get the message

Exception in thread "main" java.lang.NoClassDefFoundError: FirstExercise/jav

What do I need to do to get my file to compile?
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 692
Is your error during compilation or execution? It appears to be execution.
You compile witht the javac.exe command.
You execute with the java.exe commmand.
Please copy the full text of the console when the error occurs showing what you typed in and what happened.

The import statement is a dotted path that the compiler uses to extend the classpath to find class definitions. It concatenates that path to the classpath to find the class.

>import classes.bytecode.*;
This says to look in the folder: classes\bytecode\ for class definitions.
Giles Buist

Joined: Sep 27, 2005
Posts: 8
When you say it looks for class definitions you mean the filename.class files right?

The error occurs when compiling.

I have been fiddling a bit and now get this error (here is a copy of the dos screen)

Microsoft Windows 2000 [Version 5.00.2195]
(C) Copyright 1985-2000 Microsoft Corp.

C:\Documents and Settings\G-Force>cd c:\

C:\>cd java

C:\Java>cd javafc

C:\Java\JavaFC>javac FirstExercise.java
FirstExercise.java:6: cannot access classes.bytecode.Person
bad class file: .\classes\bytecode\Person.class
class file contains wrong class: java.lancs.Person
Please remove or make sure it appears in the correct subdirectory of the classpa
import classes.bytecode.Person; // Locate required files
1 error

Tommy Becker

Joined: Sep 22, 2005
Posts: 8
It looks like the Person class thinks it's in a different package than the one you specified. I'd try moving the Person.class to a .\java\lancs directory and then changing the import statement in your code to "import java.lancs.*;" and see how that works.
I agree. Here's the link: http://aspose.com/file-tools
subject: The NoClassDefFound error, I'm stuck
It's not a secret anymore!