• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

The NoClassDefFound error, I'm stuck

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
th.
import classes.bytecode.Person; // Locate required files
^
1 error

C:\Java\JavaFC>
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic