• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Value inside the Action Listener is not updating the field in the class.

 
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I got a problem with the action listener method. The thing is I got an Enum class and it contains three possible states of the buttons: Add, remove, and update. I want to use this for a switch. The Enum is set inside an action performed method, but it, in the end, I get a null exception. I tried setters and getters but nothing works. Have a look a the code and let me know. Perhaps the flow is wrong...

MyClass.class

The field with the type of the Enum class:



One of the action listener methods:



The setters and getters for the filed:



And of course, the switch that I try to apply and always returns a null exception:



Hope you guys can see what is wrong. Peace out!
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I get a null exception.


Please copy the full text of the error message and paste it here. It has important info about the error.

What variable has the null value?
 
Marin Capranov
Ranch Hand
Posts: 69
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Solved by actually modifying the code a bit.
I used if statements inside the button, instead of a switch.

This how it looks in the end:



Now the Enum is seen when a value is set to it.

Sorry for inconvenience!

 
New rule: no elephants at the chess tournament. Tiny ads are still okay.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic