File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Why do i get NoClassDefFound error?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why do i get NoClassDefFound error??" Watch "Why do i get NoClassDefFound error??" New topic
Author

Why do i get NoClassDefFound error??

Sandhya Deekonda
Ranch Hand

Joined: Dec 18, 2006
Posts: 34
Hi All,
I've written a java class which just reads the contents of a file.When i run that program i'm getting an error like
Exception in thread "main" java.lang.NoClassDefFoundError.Why is it so??
Code is as follows:

import java.io.*;
class FileRead
{
public static void main(String args[])
{
try{
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream("textfile.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
//Read File Line By Line
while ((strLine = br.readLine()) != null) {
// Print the content on the console
System.out.println (strLine);
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
dinesh Venkatesan
Ranch Hand

Joined: Oct 12, 2006
Posts: 134
It should work fine if you are not misspelling it. If you are new to Java do remember that Here everything is case sensitive. That is giving a command like "java fileread" is different from java FileRead.

So try it again by taking these considerations.

NoClassDefFound error will be thrown when the java interpreter is not able to find the class that you are passing as the argument.

dinesh.
Sandhya Deekonda
Ranch Hand

Joined: Dec 18, 2006
Posts: 34
I'm spelling in the correct way,still i get that error???
Sandhya Deekonda
Ranch Hand

Joined: Dec 18, 2006
Posts: 34
Is this because of not setting classpath properly if so let me know.
Thanks,
Sandhya.
Sandhya Deekonda
Ranch Hand

Joined: Dec 18, 2006
Posts: 34
Ya i got it that was because of not settiong classpath properly.
Sandhya.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why do i get NoClassDefFound error??
 
Similar Threads
command line arguments for a file
Regarding reading a file in a jsp
Reading one line from a text
to read lines inside brackets
Error printing out from a read in file.