Hello everybody,
I have a trouble with my assignment . In my assignment, the application have to read the lists of text file before performing the another taks. I want my application run independently on any computer with JVM, so it must be read the text file in the jar file.
I have rearched on internet and got some stuff, but when i applied it, my application has some error:
Here is the code:
public class ReadFile {
private String inputFile;
public ReadFile(String inputFile) {
this.inputFile=inputFile;
}
public ArrayList<String> readFile(){
InputStream input =null;
BufferedReader bufferReader=null;
ArrayList<String> list=new ArrayList<String>();
try {
input = getClass().getResourceAsStream(inputFile);
bufferReader = new BufferedReader(new InputStreamReader(input));
String line="";
while(null != (line=bufferReader.readLine())) {
list.add(line);
}
bufferReader.close();
}
catch(IOException e) {
System.out.println("IOException : " + e);
}
return list;
}
}
and:
public class Gui{
...
private String[] output= {
"sentence01.txt","sentence02.txt",
"sentence03.txt","sentence04.txt",
"sentence05.txt","sentence06.txt",
"sentence07.txt","sentence08.txt",
"sentence09.txt","sentence10.txt",
"sentence11.txt","sentence12.txt",
"sentence13.txt","sentence14.txt",
"sentence15.txt","sentence16.txt",
"sentence17.txt","sentence18.txt",
"sentence19.txt","sentence20.txt"};
private ReadFile readFile;
...
private void readSentenceFile() {
for(int i=0;i<20;i++) {
readFile=new ReadFile("Sentence/"+output[i]);
ArrayList<String> temp=new ArrayList<String>();
temp=readFile.readFile();
sentenceList.addAll(temp);
}
}
}
And here is the error:
run:
Exception in thread "main" java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:61)
at java.io.InputStreamReader.<init>(InputStreamReader.java:55)
at vn.edu.uit.assignment3.collocationdetection.ReadFile.readFile(ReadFile.java:30)
at vn.edu.uit.assignment3.collocationdetection.Gui.readSentenceFile(Gui.java:220)
at vn.edu.uit.assignment3.collocationdetection.Gui.<init>(Gui.java:87)
at vn.edu.uit.assignment3.collocationdetection.Main.main(Main.java:51)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
Here is my project file:
http://www.mediafire.com/?jjgoywjlg1t
Any suggestion ?
Thanks in advance.