wood burning stoves 2.0
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

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "NoClassDefFoundError" Watch "NoClassDefFoundError" New topic


John King

Joined: Dec 19, 2002
Posts: 5
I am testing one java class. Here is what I did:
C:\>cd C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src
C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src>javac FileDemo.java
C:\jakarta-tomcat-4.1.12-src\webapps\ROOT\begjsp-ch14\src>java FileDemo
Exception in thread "main" java.lang.NoClassDefFoundError: FileDemo
Any idea I got this exception? Thanks in advance
Greg Charles

Joined: Oct 01, 2001
Posts: 2867

I'd guess that FileDemo is in a package. Either edit the code to remove the package designation, or compile it with:
javac -d . FileDemo.java
then run with:
java com.whatever.the.package.is.FileDemo
Jessica Sant

Joined: Oct 17, 2001
Posts: 4313

"Tedy Bear"-
Two things...
1st thing:
Welcome to the JavaRanch! Please adjust your displayed name to match the JavaRanch Naming Policy.
You can change it here.
2nd thing:
interesting error -- I can't reproduce it exactly... but when you look in that folder -- do you see the compiled .class file?
...again welcome to the JavaRanch!
John King

Joined: Dec 19, 2002
Posts: 5
I changed my profile
There is no package.
Here is the source code:
import java.io.*;
public class FileDemo {
public static void main (String [] args) throws IOException {
// Create instances of File objects for directory
// and file entries
File dir = new File(File.separator + "Wrox" + File.separator
+ "docs");
File f1 = new File(dir, "test1.txt");
File f2 = new File(dir, "test2.doc");
File f3 = new File(dir, "test3.txt");
//FileDemo f = new FileDemo();
// Create directory and files
System.out.println("Directory \\Wrox\\docs created");
System.out.println("Files \"test1.txt\" and \"test2.doc\" created");
// Get file attributes
System.out.println("\nAttributes of \"test1.txt\" \n" +
"\n\"test1.txt\" exists: " + f1.exists() +
"\n\"test1.txt\" is a file: " + f1.isFile() +
"\n\"test1.txt\" is a directory: " + f1.isDirectory() +
"\nCan read from \"test1.txt\": " + f1.canRead() +
"\nCan write to \"test1.txt\": " + f1.canWrite() +
"\nThe absolute path of \"test1.txt\": " + f1.getAbsolutePath());
// Rename test2.doc to test3.txt
System.out.println("\nThe name of the file object f2 is "
+ f2.getName());
System.out.println("Renaming :\"test2.doc\" to \"test3.txt\"");
System.out.println("The name of the file object f3 is "+f3.getName());
// Delete all files and directory
System.out.println("\nDeleting files and directory ");
System.out.println("The file \"test1.txt\" is deleted: "
+ f1.delete());
System.out.println("The file \"test3.txt\" is deleted: "
+ f3.delete());
System.out.println("The directory docs is deleted: "
+ dir.delete());
//FileDemo f = new FileDemo();
I agree. Here's the link: http://kickstarter.com/rocket-mass-heater
subject: NoClassDefFoundError