This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
posted
0
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
posted
0
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
posted
0
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