This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Answer
Posted by Gokulraj on November 20, 2000 at 4:59 AM
> Does anyone know why a NullPointerException might be thrown. I am trying to copy the details from an array into a text file using the following code; > try > {FileWriter fw = new FileWriter "C:\\Java_Files\\Customers_Java.txt"); > PrintWriter pw = new PrintWriter(fw); > > for (i = 1; i <= customers_held; i++) > { > pw.println(i); > pw.println(name[i]); > pw.println(street[i]); > pw.println(town[i]); > pw.println(county[i]); > pw.println(postcode[i]); > } > fw.close(); > }catch(FileNotFoundException e){ > System.out.println("Error: Can't find file specified!"); > }catch(IOException e){ > System.out.println("I/O Error: " + e); > } > Any help would be appreciated! > Many thanks I think the Error was there in FileWriter instantiation...u missed a left parenthesis...Null Pointer Exception will occur whenever u missed to instantiate the object..
check whether u declared the variable customers_held...and check every variable bye Gokulraj
Replies:
|