I am trying to print strings into a file. What have I done wrong and it always gives me a NullPointException? I believe my exceptions catch something or an argument is needed and I dont enter it. But where?
I have writen this code, that contains the main function.
EDIT: Getting error in the second line from the bottom some.items[0]="Testing One!";
.
import java.io.*;
public class StringPrinter {
public String[] items;
public File file;
public StringPrinter(String fileName){
file = new File(fileName);}
public void toFile(){
try{
PrintWriter pw = new PrintWriter(new FileWriter(file, false));
for (String st:items){
pw.println(st);
}
}
catch(Exception exception){}
}
public static void main(String args[]){
StringPrinter some=new StringPrinter("Workyou.txt");
some.items[0]="Testing One!";
some.items[1]="Testing Two!";
some.toFile();
}
}