title: Why I still have FileNotFoundException is never thrown in body of corresponding try statement?
body: <p>For my application, I keep getting this compilation error saying <code>**FileNotFoundException is never thrown in body of corresponding try statement**</code> I have this within the actionlistener event handling part so I'm not sure whether it's the correct way to do it.</p>
  
  <p>I do understand that the catch exception bit is related to the try statement and it must be so called related so in this case, I'm initiating a new File object class from the user's input but the error stays.</p>
  
  <p>Could you guys give me some advice as I'm still a novice and I just started on <code>GUI</code> not long ago?</p>
  
  <p>Main class:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  import java.util.*;
  import java.io.*;
  
  class MyFileLister extends JPanel implements ActionListener {
  
  private JLabel prompt = null;
  
  private JTextField userInput = null;
  
  private JTextArea textArea = null;
  
  public MyFileLister()
  {
      prompt = new JLabel("Enter filename: ");
      prompt.setOpaque(true);
      this.add(prompt);
  
      userInput = new JTextField(28);
      userInput.addActionListener(this);
      this.add(userInput);
  
      textArea = new JTextArea(10, 30);
      textArea.setOpaque(true);
      JScrollPane scrollpane = new JScrollPane(textArea);
      this.add(textArea, BorderLayout.SOUTH);
  }
  
  Scanner s = null;
  File af = null;
  
  public void actionPerformed(ActionEvent f)
  {
      try
      {
          af = new File(userInput.getText());
      }
      catch(FileNotFoundException e)
      {
          System.out.println("Error");
      }
  }
  }
  </code></pre>
  
  <p>And the driver class:</p>
  
  <pre><code>import java.util.*;
  import java.awt.*;
  import javax.swing.*;
  
  
  class TestMyFileLister {
  
  public static void main(String [] args)
  {
      MyFileLister thePanel = new MyFileLister();
  
      JFrame firstFrame = new JFrame("My File Lister");
  
      firstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      firstFrame.setVisible(true);
      firstFrame.setSize(500, 500);
      firstFrame.add(thePanel);
  
  
  }
  }
  </code></pre>