| Author |
Array List is Printing Out the Exact Same Thing
|
Toshiro Hitsuguya
Greenhorn
Joined: May 15, 2009
Posts: 19
|
|
My problem is that whenever I run this everything runs fine. Except when I print the avalible books, it prints the exact same book 4 times. I know that it creates an array, because it prints out four times. However, I can't figure out why it prints out the last book added only.
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16482
|
|
|
No, there are four books in your example. Your problem is not that, your problem is that each book should have its own title and its own "borrowed" flag. But your Book class doesn't work like that. I will just give you a hint that the problem is with the declaration of those two fields.
|
 |
Toshiro Hitsuguya
Greenhorn
Joined: May 15, 2009
Posts: 19
|
|
|
Thanks a lot Phil. I got my code up and running and works fine. I am having a weird error. I put the firstLibrary.printAddress() into System.out.println() and it is printing out null. I was looking at the structure of my Book class for getTitle() and the Book constructor and it is the exact same structure.
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16684
|
|
Brian Wimpsett wrote:I am having a weird error. I put the firstLibrary.printAddress() into System.out.println() and it is printing out null. I was looking at the structure of my Book class for getTitle() and the Book constructor and it is the exact same structure.
Well, a good place to look is at the constructor...
Care to explain what you are trying to do?
Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
Toshiro Hitsuguya
Greenhorn
Joined: May 15, 2009
Posts: 19
|
|
|
Sure, I am trying to set the value of address to the argument in the constructor.
|
 |
Sean Clark
Rancher
Joined: Jul 15, 2009
Posts: 377
|
|
Brian Wimpsett wrote:Sure, I am trying to set the value of address to the argument in the constructor.
Are you sure?
|
I love this place!
|
 |
Toshiro Hitsuguya
Greenhorn
Joined: May 15, 2009
Posts: 19
|
|
|
Never mind. I had the values reversed. it should be address = street Thanks anyway.
|
 |
 |
|
|
subject: Array List is Printing Out the Exact Same Thing
|
|
|