• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable rectify NullPointerException  RSS feed

 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

The below program is to develop an accessibility heuristic for Knight's Tour problem. (Let me know if I need to explain KT problem )



This is throwing java.lang.NullPointerException
at KinghtsTour.KnightsCleverTour.main(KnightsCleverTour.java:22)

Please help.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Well, this stacktrace...

This is throwing java.lang.NullPointerException
at KinghtsTour.KnightsCleverTour.main(KnightsCleverTour.java:22)


Gives you the exact file, method, and line, where the exception occurred. It would be a good idea to start there.

However... just looking at your application for a few seconds... here is a hint. Where did you instantiate any chessboard objects?

Henry
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ChessBoard object is instantiated at line 6.

Note:
Line 22 is actually

 
N. Priore
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
john eipe wrote:ChessBoard object is instantiated at line 6.

Note:
Line 22 is actually



On line 6 you are instantiating an array.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you create a new array this way, all of its elements are null (or 0 for numbers, '\0' for chars, false for booleans). You'll need to initialize each element separately:
 
John Eipe
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right! I should have remembered that about arrays of objects.

Thanks,
John Eipe
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!