• 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

Unable to add an instance of another Class from TextFields

 
Ranch Hand
Posts: 186
1
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings, I'm attempting to add an object's String to a TextArea in a Swing interface. I'm brand new to Swing as I'm familiar with JavaFX (don't know why my professor wants us to use Swing but oh well). For some reason, the String parsed from my variables is showing up as null, let's say for instance, I add a plant, it says (based off of my Plant class toString method, it gives the following String: "This plant's name is null with a color of: null with a unique ID of: null" Please let me know if further clarification is needed as I'm typing this hastily. I'm a bit desperate at this point.


GUI:



Plant Class:

 
Marshal
Posts: 79177
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your equals method is incorrect because you have not overridden hashCode in parallel.
Are you passing null to any constructors or setXXX methods? That is the only way you could get those three fields to point to null. I suggest you start by changing all the places where fields are assigned or reassigned to read
myField = Objects.requireNonNull(myParameter);
That shou‍ld soon tell you where you are getting the nulls.
In fact, I think you shou‍ld be protecting all reference type fields from having null assigned to them in all your classes like that.
I can see where you are getting values out of your text fields, but where are you using those values? Why are those three Strings fields rather than local variables? If there were local variables, you would find out about the problem soon enough because you would get a compiler error about not initialising them.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic