• Post Reply Bookmark Topic Watch Topic
  • New Topic

Array and for loop troubles  RSS feed

 
Gus Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, I'm having some problems with this code, namely that it won't store the created objects in the array and keeps declaring the array to have null objects in it. Any help would be much appreciated.


I'm probably missing something really obvious. On construction of the Library class it's supposed to create and store as many objects as I put in the shelfSpace integer, but it declares a null. Thanks in advance.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12564
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have declared the Textbook bookshelf twice...once as a member, once as a local variable inside the constructor. So, when you leave the constructor, the local one goes out of scope (with all the objects), and the member variable is (still) empty.

Try removing the "Textbook []" from line 9.
 
Gus Smith
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much, that fixed it. Very much appreciated :)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!