This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why do i get NoClassDefFound error??

 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 134
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm spelling in the correct way,still i get that error???
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this because of not setting classpath properly if so let me know.
Thanks,
Sandhya.
 
Sandhya Deekonda
Ranch Hand
Posts: 34
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ya i got it that was because of not settiong classpath properly.
Sandhya.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic