Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NoClassDefFoundError

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am testing one java class. Here is 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();
}
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
No error message in compiling. But when I run it, I had NoClassDefFoundError. Any idea why I got this exception? I suspect the path problem. Thanks in advance
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whoa deja vu! OK, so it's not in a package. You might try:
set CLASSPATH=.
before you run it. However, I just compiled and ran it without any CLASSPATH variable being set. Can you run any Java programs on your system? Maybe something is fundamentally wrong with your set up.
 
John King
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I run a lot of JSP and Javabean in my machine without any problem. I am using Forte as well as command line to compile it.
 
John King
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I messed CLASSPATH when I installed Tomcat. It was:
C:\jakarta-tomcat-4.1.12-src\common\lib\servlet.jar
It should be:
C:\jakarta-tomcat-4.1.12-src\common\lib\servlet.jar;.
Now it works. Thanks for your help.
 
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic