Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try the following:</p> <pre><code>public GUI () throws Exception{ this.setTitle("NYWM Cross Reference Application"); this.setSize(400,100); this.setVisible(true); this.setLocationRelativeTo(null); buttonHolder = new Panel (new BorderLayout()); this.add(buttonHolder); crossReference = new Button ("CrossReference"); generateHPD = new Button ("Generate HPD"); buttonHolder.add(crossReference, BorderLayout.NORTH); buttonHolder.add(generateHPD, BorderLayout.SOUTH); // NOTE the order below has been flipped!!!! createExcelSheet (log,"C:/Log.xlsx", "Log"); createExcelSheet(sheet,"C:/Spreadsheet.xlsx", "Spreadsheet"); crossReference.addActionListener(new crossReferenceButtonListener()); generateHPD.addActionListener(new generateHPDButtonListener()); } </code></pre> <p>In your original code, you create the button and then add the action listener:</p> <pre><code>crossReference.addActionListener(new crossReferenceButtonListener()); </code></pre> <p>However, it's only after adding the <code>crossReferenceButtonListener</code> that you call <code>createExcelSheet</code>, which is where the <code>Workbook</code>s are actually being instantiated. And that <code>crossReferenceButtonListener</code> wanted to use fields on the <code>Workbook</code>s, but they were null, thus your <code>NullPointerException</code>.</p> <p>By calling the <code>createExcelSheet</code> methods before you add that <code>crossReferenceButtonListener</code>, you will ensure that both <code>log</code> and <code>sheet</code> have been created by the time the <code>crossReferenceButtonListener</code> tries to use 'em.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload