• Post Reply Bookmark Topic Watch Topic
  • New Topic

Objects showing null  RSS feed

 
Megan Admire
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to pass information from a file that contains book titles with Year, Publisher, ISBN, Price, Pages, and Authors. But when I run my program and test it using the statement , I'm getting all my information equal to null. Please help.

Here is my main program



Here is my book class:



There is more code but hoping that this alone will let people see where I'm having issues. Thanks for any help. Really appreciate it! ^_^
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In line 28 of your class Main, you create a new Book, in which all the member variables are set to null.

Then you do a whole bunch of things in lines 29 to 52. You read data from a file, create Book and JournalPaper objects that you put into two arrays.

And then in line 54 you print the Book object which you created in line 28. But that Book object still has all its member variables set to null.
 
Knute Snortum
Sheriff
Posts: 4091
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you're not setting "book" anywhere, you're setting "read[i]".
 
Megan Admire
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sooo VERY much Jesper! Seems like when I'm stressed I miss simple things like that. I really do appreciate your help ^_^. Thanks again.
 
Campbell Ritchie
Marshal
Posts: 55793
164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are all sorts of other things. Why have you got so many things marked static? Why are you creating new arrays inside your loops (lines 29-30)? Why are you using String Tokenizer at all?

And welcome to the Ranch
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!