NullPointerException when dealing with files
-
Gives NullPointerException to work with the files, and it doesn't work, help me figure it out. I'm building a variable. file where the file is recorded by the chosen user in the same class,
File file; public File getFile() { return file; } if (cmd.equals("Quelldatei auswählen")) { JFileChooser fileChooser = new JFileChooser(); fileChooser .setFileSelectionMode(JFileChooser.FILES_ONLY); int ret = fileChooser.showDialog(this, "auswählen"); if (ret == JFileChooser.APPROVE_OPTION) {
file= fileChooser.getSelectedFile().getAbsoluteFile(); contentPane.add(new JLabel("Quelldatei ist: " + file));
and challenge him from the classroom method by setting up the object of this class to challenge this file through. gd.getFile()
GUIDialog gd;
public void doit() {
try {
gd=new GUIDialog();
in = new BufferedReader(new FileReader(gd.getFile()));
but when a cat is pressed on the button, it must take this transferable file and transform it, it's NullPointerException, pointing on this line. in = new BufferedReader(new FileReader(gd.getFile()));what's being done here is wrong, help counsel.
-
Then you can simply make a comparison in a separate method, and in the designer, for example, make it:
public File getFile() { sravnenie(); return file; }
Thank you very much, but it's only through a 1-block strike.