This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes whats the error! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "whats the error!" Watch "whats the error!" New topic
Author

whats the error!

chitra ratnawat
Greenhorn

Joined: May 24, 2001
Posts: 6
Program given below is compiling but at run time its throwing Exception
Exception in thread "main" java.lang.NoClassDefFoundError : FileWriter
i am not able to catch it .can any body answer it?

import java.io.*;
class FileWriterDemo{
public static void main(String ar[]) throws Exception{
String s ="abcdefghi";
int a = s.length();
char c[]= new char[a];
s.getChars(0,a,c,0);
FileWriter fw = new FileWriter("in.txt");
for(int i=0;i<c.length;i++){>
fw.write(c[i]);
}
//fw.close();
}
}
nitin sharma
Ranch Hand

Joined: Feb 24, 2001
Posts: 290
import java.io.*;
class FileWriterDemo
{
public static void main(String ar[]) throws Exception
{
FileWriter fw;
String s ="abcdefghi";
int a = s.length();
char c[]= new char[a];
s.getChars(0,a,c,0);
fw = new FileWriter("in.txt");
for(int i=0;i<a;i++)>
{
fw.write(c[i]);
}
}
}
The above given code is working fine.I have compiled it and no runtime exception was thrown.
Shiraz Bhagwagar
Greenhorn

Joined: Mar 28, 2001
Posts: 27
This is the same question I had posted on the Java in General(Beginner) forum. Loaded all possible patches and reinstalled Java. Of no use. It still doesnot work. Can anybody figure this out???
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
This code compiles fine and runs fine (well, without an input file it doesn't DO much but . . . ).
If it compiled fine, that means that your path statement is set up nicely. If it can not find the SAME files when it runs, that means that your classpath does not have all the same stuff in it that your path does. In this case it is one of the JRE classes so make sure that you classpath has c:\jdk1.3.0\bin (or whatever you called it) in the path as well as the location of the classes that YOU are compiling.

"JavaRanch, where the deer and the Certified play" - David O'Meara
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: whats the error!
 
Similar Threads
creating files in directory
reverse the text file and write
JavaCaps Test 2, Question # 33
FileWriter, File Created but no content
JavaCaps Test 2, Question # 34