Use array as constructor for array of classes

时间:2017-04-10 01:24:15

标签: java

I've been trying to get this working for far too long. I am to use an array of strings to construct an array of "sentence" classes by using the string as part of the constructor. Can anyone help me out? public class FileConverter {

private final String input;
private final String output;
private boolean inputEncrypted;
private ArrayList<Sentence> y;

public FileConverter(String input, String output, boolean inputEncrypted) {                
    this.input = input;
    this.output = output;
    this.inputEncrypted = inputEncrypted;
}

// this method creates an array of sentences from input
public boolean readInput() {
    String[] x = input.split("\\.");        

   for(String x1:x){
       Sentence a = new Sentence(x1);
        y.add(a);
   }
    return false;
}

y.add(a) is giving me a null pointer exception. I've tried a few different ways to do this and I can't seem to figure it out.

0 个答案:

没有答案