title: Why am I getting a null pointer exception creating a file?
body: <p>I am creating a file in a class and I want to pass the file path to use the file in another class. I am getting the following error when I try to use the file in another class:</p>
  
  <p>Does anyone know why it cannot see the file? 
  The string saveFilePath is initialized at the top of the Mainframe class. If I hard code the path it works fine but when I pass the path as the string saveFilePath I get the error. Thanks</p>
  
  <pre><code>   private void saveFile() {
      JFileChooser fileChooser = new JFileChooser();
      FileFilter wavFilter = new FileFilter() {
          @Override
          public String getDescription() {
              return "Sound file (*.WAV)";
          }
  
          @Override
          public boolean accept(File file) {
              if (file.isDirectory()) {
                  return true;
              } else {
                  return file.getName().toLowerCase().endsWith(".wav");
              }
          }
      };
  
      fileChooser.setFileFilter(wavFilter);
      fileChooser.setAcceptAllFileFilterUsed(false);
  
      int userChoice = fileChooser.showSaveDialog(this);
      if (userChoice == JFileChooser.APPROVE_OPTION) {
          saveFilePath = fileChooser.getSelectedFile().getAbsolutePath();
          if (!saveFilePath.toLowerCase().endsWith(".wav")) {
              saveFilePath += ".wav";
          }
  
          File wavFile = new File(saveFilePath);
  
          try {
              recorder.save(wavFile);
              buttonPlay.setEnabled(true);
              Keyup.setEnabled(true);
              Keydown.setEnabled(true);
              btnSave.setEnabled(true);
              getKey.setEnabled(true);
  
  
          } catch (IOException ex) {
              JOptionPane.showMessageDialog(Mainframe.this, "Error",
                      "Error saving to sound file!",
                      JOptionPane.ERROR_MESSAGE);
              ex.printStackTrace();
          }
      }
  }
  
  
  public class notehandle extends Mainframe{
  
  
  String s = saveFilePath;
  File f = new File(s);
  float pitchInHz;
  
  public float note() {
  
      PitchDetectionHandler pdh = new PitchDetectionHandler() {
  
          public void handlePitch(PitchDetectionResult result,AudioEvent e) {
  
             pitchInHz = result.getPitch();
  
  
  
          }
  
  
  
      };
  
      AudioDispatcher dispatcher = null;
      try {
          dispatcher = AudioDispatcherFactory.fromFile(f, 1024, 0);
      } catch (UnsupportedAudioFileException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      AudioProcessor p = new PitchProcessor(PitchEstimationAlgorithm.FFT_YIN, 48000, 1024, pdh);
      dispatcher.addAudioProcessor(p);
      new Thread(dispatcher,"Audio Dispatcher").start();
  
  
      return pitchInHz;
  
  
  
  }
  </code></pre>
  
  <p>}</p>