Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is this error trying to tell me in NetBeans?
    text
    copied!<p>So I've been working on my program, using GUI for the first time in java. I think I have everything how it supposed to be, but is giving me one error:</p> <pre><code>Exception in thread "main" java.lang.NullPointerException at GUIProgram.&lt;init&gt;(GUIProgram.java:41) at Inventory.main(Inventory.java:12) Java Result: 1 BUILD SUCCESSFUL (total time: 3 seconds) </code></pre> <p>I don't know what exactly I have to do, I keep trying to fix it, but I can't.</p> <p>If you need more information to find out what is wrong, please let me know.</p> <p><strong>Edit</strong> (copied from comment)</p> <pre><code>Product[] array = new Product[table.length]; float total = 0; float fee = 0; for(Product p: array) { total += p.getTotal(); fee += p.getRestockingFee(); } </code></pre> <p>This is the GUIProgram class I am building. </p> <pre><code> import javax.swing.*; import java.awt.*; public class GUIProgram extends JFrame { public GUIProgram() { super("Welcome to the Inventory Program"); setLayout(new FlowLayout()); String[] columnNames = {"Item", "Item No.", "Unit", "Price"}; Product[] table = new Product[5]; table[0] = new Product("chocolate", 1023, 124, 1.50f); table[1] = new Product("ice cream", 1543, 170, 3.35f); table[2] = new Product("milk", 1265, 230, 2.40f); table[3] = new Product("orange juice", 1653, 199, 0.60f); table[4] = new Product("cereal", 1534, 176, 3.50f); for (int i = 0; i &lt; table.length; i++) { JTextField textfield1 = new JTextField(table.length); add(textfield1); float total = 0; float fee = 0; for(Product p: table) { total += p.getTotal(); fee += p.getRestockingFee(); } JTextField textfield2 = new JTextField(table.length); textfield2 = new JTextField(String.format("The total value of the Fruits Inventory is: %.2f", total)); add(textfield2); JTextField textfield3 = new JTextField(table.length); textfield3 = new JTextField(String.format("The total restocking fee is: %.2f", fee)); add(textfield3); } } } </code></pre> <p>I'm just trying to build a GUI for this array.</p>
 

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