• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Objects showing null

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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! ^_^
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 7113
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 76419
365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Make yourself as serene as a flower, as a tree. And on wednesdays, as serene as this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic