• Post Reply Bookmark Topic Watch Topic
  • New Topic

Be the compiler: BookTestDrive  RSS feed

 
Vikram Reddy Merugu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, this exercise compiles fine. But I get null pointer exception when I try to run it. Since the question is whether the program will compile or not, this is not an exercise question anymore at this point.

Here is the code given on page 63:





I put each class in seperate file with proper names.
This is the error message I get:


Where am I going wrong?
 
Junilu Lacar
Sheriff
Posts: 11476
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

On line 4 you are only creating an array that can hold instances of Book. An array of object references like Book will be initialized to have all its elements set to null. So when you try to dereference the null value on line 6 to access the title field, well... you've seen what happens next.
 
Vikram Reddy Merugu
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, thanks for the welcome. Oops not sure how I missed such an obvious mistake. I guess I need to re-read the chapter. Read it just two days ago.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!