0

I am having a really hard time finding what is causing this AWT-EventQueue-0 NullPointerException error. I have narrowed it down to somewhere in these 2 methods. I think from my reading that AWT has to do with action events, so my guess was in the actionPerformed method, but your guess is as good as mine. This question is definitely not a duplicate because it is completely unique to this code.

  public void actionPerformed(ActionEvent e) {
    int saveType = 0;
    String buttonString = e.getActionCommand();

    if (buttonString.equals("Shutdown >>")) {

        shutdownServer();
    }

    else if (buttonString.equals("Save >>")) {

        JFileChooser fc = new JFileChooser();
        fc.setCurrentDirectory(new java.io.File("."));
        fc.setDialogTitle("Save file");
        FileNameExtensionFilter filter = new FileNameExtensionFilter(".txt", "txt", "text");
        fc.setFileFilter(filter);

        int select = fc.showSaveDialog(null);
        if (select == JFileChooser.APPROVE_OPTION)
        {
            File fi = fc.getSelectedFile();
            fileName = fi.getPath();

            if (fileRB.isSelected()) {
                dbDisplaytx.setText("REPORT SAVED TO FILE");
                saveType = 1;
            }
            else if (databaseRB.isSelected()) {
                dbDisplaytx.setText("REPORT SAVED TO DATABASE");
                saveType = 2;
            }
             else if (bothRB.isSelected()) {
                dbDisplaytx.setText("REPORT SAVED TO BOTH FILE & DATABASE");
                saveType = 3;
            }
             else {
                // stub to test radio button
                dbDisplaytx.setText("WRONG SELECTION");
             }
        }
        produceProfileReport(saveType);
    }

}

This is the second method

    private void produceProfileReport(int saveType) {
       OperationalProfileReportGeneratorFactory reportGeneratorFactory = SimpleOperationalProfileReportGeneratorFactory
            .getInstance();
    OperationalProfileReportGenerator reportGenerator = reportGeneratorFactory
            .newReportGenerator();

    //Saves to file
    if(saveType == 1 || saveType == 3){
        try {
            FileWriter writer = new FileWriter(fileName);
            writer.write(reportGenerator.generateReport(database));
            writer.flush();
            writer.close();
        } catch (IOException ioe) {
            display.displayMessage(UNABLE_TO_WRITE_PROFILE_REPORT_ERROR_MESSAGE
                    + fileName);
        } // try...catch (IOException)
    }
    //Saves to database
    else if(saveType == 2 || saveType == 3) {
        try {
            FileWriter writer = new FileWriter(fileName);
            //reportGenerator.generateReport(database)
            writer.write("WRITE TO DATABASE");
            writer.flush();
            writer.close();
        } catch (IOException ioe) {
            display.displayMessage(UNABLE_TO_WRITE_PROFILE_REPORT_ERROR_MESSAGE
                    + fileName);
        }
    }
}

generateReport()

 public String generateReport(OperationalProfileDatabase database) {

    synchronized (database) {
        if (database.getNumberOfOperationalProfiles() == 0) {
            return NO_PROFILES_RECEIVED_REPORT; 
        } else {
                    database.toSQL();
            return database.toString();
        } // if (database.getNumberOfOperationalProfiles() == 0)
    } // synchronized (database)

}

STACK TRACE

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at oplogger.server.reportgen.SimpleOperationalProfileReportGenerator.generateReport(SimpleOperationalProfileReportGenerator.java:49)
at oplogger.server.ui.AdministrationTerminal_GUI.produceProfileReport(AdministrationTerminal_GUI.java:130)
at oplogger.server.ui.AdministrationTerminal_GUI.actionPerformed(AdministrationTerminal_GUI.java:279)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
webminer07
  • 293
  • 4
  • 8
  • 25
  • The stack trace shows that the error happens in the `generateReport` method, which you haven't shown. – Boann Oct 24 '15 at 11:54
  • Thanks, yeah i knew the actual error was happening on the line synchronized (database) But thought it was coming from something previous in the earlier classes. I'm thinking it might be because database is null. – webminer07 Oct 24 '15 at 12:00

0 Answers0