aspose file tools*
The moose likes Beginning Java and the fly likes Values are assigning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Values are assigning null" Watch "Values are assigning null" New topic
Author

Values are assigning null

Miryanda Johnson
Greenhorn

Joined: Dec 08, 2011
Posts: 3
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.



Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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.


SCJP
Visit my download page
Miryanda Johnson
Greenhorn

Joined: Dec 08, 2011
Posts: 3
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

Joined: Oct 21, 2000
Posts: 4347
    
    2

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

Joined: Dec 08, 2011
Posts: 3
All my variables were declared as static. That was causing the overriding I was seeing
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

good job Miryanda! static variables are the exception not the norm. most of the time you want an instance variable.
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4347
    
    2

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.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40052
    
  28
Lots of books show you static fields throughout, but that is not usually good practice.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Values are assigning null