• 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

NoClassDefFoundError

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 3063
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
dir.mkdirs();
System.out.println("Directory \\Wrox\\docs created");
f1.createNewFile();
f2.createNewFile();
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\"");
f2.renameTo(f3);
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 can't beleive you just said that. Now I need to calm down with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic