• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

whats the error!

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic