• 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

Values are assigning null

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello! I'm hoping someone can help me demystify why the values are returning null. I know this has to be rather obvious but I'm not seeing it. Any help is appreciated.

I believe the issue is occuring under the addContact() method when the values are being assigned. I'm using an ArrayList to send all the information to the constructor, but whatever I'm doing is either overrode or returning a null value.



 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm in no condition to figure this out right now, but i just wanted to say. null pointer exceptions always seem obvious after you have solved them, but before that they can drive you crazy.
 
Miryanda Johnson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was able to get the values to stop assigning null values to the variables, by chagning the constructor:



However, whenever calling addContact() twice, the values are being overridden.




I want it so row one is all displaying whatever is entered, then row two displays whatever was entered the second time.

Any help?
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good job fixing the constructor i didn't notice you were doing it backwards(wrong). someone else will have to help with the other problem. i don't know the Scanner class and as i implied i am kind of drunk.
 
Miryanda Johnson
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All my variables were declared as static. That was causing the overriding I was seeing
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
good job Miryanda! static variables are the exception not the norm. most of the time you want an instance variable.
 
Randall Twede
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and welcome to the ranch. and don't worry if you question seems obvious or stupid. you should see some of the questions i have asked here.
 
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lots of books show you static fields throughout, but that is not usually good practice.
 
reply
    Bookmark Topic Watch Topic
  • New Topic