• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Unable rectify NullPointerException

 
Ranch Hand
Posts: 215
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ChessBoard object is instantiated at line 6.

Note:
Line 22 is actually

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22850
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right! I should have remembered that about arrays of objects.

Thanks,
John Eipe
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic