I have a piece of code in Java Swing which browses a txt file and then prints the content of the file in a text area. This is the method which does the work. For some reason which I am overlooking most probably, I am getting a null pointer exception every time I am testing the code. Can you please tell me what I have done wrong or maybe provide a link?
private void showText() {
try{
//filePathInputField.setText(new File(file.getFile()).getAbsolutePath());
FileReader fr = new FileReader(fileInputPathField.getText());
BufferedReader br = new BufferedReader(fr);
while((sourceText = br.readLine()) != null){
sourceText += br.readLine();
}
sourceTextArea.setText(sourceText);
} catch (Exception ex){
showMessage();
ex.printStackTrace();
}
}
The Error that i received after changing the code slightly from your suggestions are:
java.io.FileNotFoundException: D:\Java\GUI Project Files\Crypto\Audio Specs.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:138)
at java.io.FileInputStream.<init>(FileInputStream.java:97)
at java.io.FileReader.<init>(FileReader.java:58)