I need some help. This is my function:
public String[] getLines(String filename) {
String[] returnVal = null;
int i = 0;
try {
BufferedReader br = new BufferedReader(new FileReader(new File(filename)));
for(String line; (line = br.readLine()) != null; ) {
// process the line.
returnVal[i] = line;
i++;
}
br.close();
}
// Catches any error conditions
catch (Exception e)
{
debug.error("Unable to read file '"+filename+"'");
debug.message(e.toString());
}
return returnVal;
}
which should return me String[] array with all the lines from a specified file. But I only get exception as return:
java.lang.NullPointerException
and when I try to print the result it is null. Any ideas? Thanks!
returnVal[i]-->returnVal is null. You have to initialize it.