0

I am using the following code, and I am trying to call an action from another action.

// Full code: https://github.com/neorai/Notepad/blob/master/src/notepad/Notepad.java

private void MenuGuardarActionPerformed(java.awt.event.ActionEvent evt) {                                            
     if ("nuevo".equals(MenuNuevo.getName())) {
         MenuGuardarComoActionPerformed(evt); //<-- problem
     }else{
         try {
             File fileToSave = jFileChooser1.getSelectedFile(); // ruta del archivo a leer
             FileWriter escribir;
             escribir = new FileWriter(fileToSave.getAbsolutePath(), true); 
             escribir.write(TextArea.getText()); // escribir en archivo
             jTabbedPane1.setTitleAt(0, jFileChooser1.getName(fileToSave)); //establecer el nombre del archivo en pestaña de jtabbedpanel, 0 es la posicion de la pestaña en el array
             escribir.close(); //cerrar archivo
         } catch (IOException ex) {
             Logger.getLogger(Notepad.class.getName()).log(Level.SEVERE, null, ex);
         }
     }
} 

How could I call that action from another action?

apaderno
  • 26,733
  • 16
  • 74
  • 87
rai
  • 15
  • 5
  • You would solve this NPE (null pointer exception) the same way as you solve any other NPE. Please read the link the duplicate to learn the details. – Hovercraft Full Of Eels Mar 17 '18 at 02:04
  • Also, the statement you pointed to is just a method call. You can't get the NPE on that statement. The problem would be somewhere in the method. So look at your trace and get the proper line number for you to start looking at. Also, method names should NOT start with an upper case character. And variable names should NOT start with an upper case character. Learn Java naming conventions.Finally, why do you have an "if statement" in an ActionListener. Each component should have a unique listener so there should be no need for the if statement. – camickr Mar 17 '18 at 02:21

0 Answers0