• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

whats the error!

 
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();
}
}
 
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.
 
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???
 
"The Hood"
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.
 
He was expelled for perverse baking experiments. This tiny ad is a model student:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic