Skip to content
Advertisement

No output after button click, since the variable doesn’t exist?

I wanted a frame with one TextArea and one Button. When I press the button, the TextArea should show a food menu of 5 Pizzas, well it shows nothing at all, except for the console which shows

JavaScript

In the method windowsStart() the objects exists and are adjustable. In the actionPerformed()Method the objects are … kind of invisible, not existing?

JavaScript

The TextArea should get the value of the ArrayList

Advertisement

Answer

Your exception occurs in : at de.kvwl.pizza.MainFrame.actionPerformed(MainFrame.java:54)

This action is linked during windowStart with b.addActionListener(mFrame);.

But What I see is that you pass another instance of MainFrame called mFrame as parameter (as an ActionListener). This mFrame never load the list with

JavaScript

So in short, you have two instance MainFrame:

  • one created and use to call windowStart
  • one created in windowsStart and use to execute actionPerformed.

This last one never load the list of data. Explaining why your list is populated in windowStart but not in actionPerformed, you are actually using two distinct instance MainFrame with two list pPizza.

You can correct this by removing this second instance and use this, the first instance as an ActionListener

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement