Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
Adithya Bhat
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys i was working with multidimensional array and when i try to execute this following program i get this error.Can you guys please help me with this one.

java.lang.NullPointerException
at blur.copy(blur.java:15)
at blur.main(blur.java:30)

 
Jelle Klap
Bartender
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you suppose the data memer variable of the multi object created at line 10 refers to after the constructor completes?
Does that change anywhere in the body of the copy method?
 
Vivek Singh
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Adithya Bhat wrote:

Hey you have not initialized the res.data so it throws NULL POINTER Exception.
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go through every object reference in that line (15) and insert a line before it rather like this
That will tell you which object was null. You may be able to miss out the != null bits in that line.
 
Adithya Bhat
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys,code's working now.
But i don't get what Campbell is saying.
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is your code with one line added:Correct the spelling and compiler errors (if any), run that, and see whether you get a helpful output just before the Exception.>
 
Adithya Bhat
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Campbell,now i get what you are saying.
 
Campbell Ritchie
Sheriff
Posts: 48402
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome

And welcome as a new member to JavaRanch
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic