This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

whats the error!

 
chitra ratnawat
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic