Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Null Pointer Exception Issue in Java Maze  RSS feed

 
Liam Mass
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for being so friendly on this community! I think I'm almost done my maze. I have a file called MazeRunner with preprogrammed mazes another file called MazeUtils that allows the user to choose and play a maze, by moving an "o" through "x's" that represent walls. I'm experiencing one last issue, though. Upon entering a direction for the "o" to move, I get an error that reads: 'Exception in thread "main" java.lang.NullPointerException .' The error points to the part of code for each direction that says:

if(map[location[a]-1][location[b]]==1)
System.out.println("There's a wall here!");

For example, if I type in "u" to go up, the error will point to line 90 in MazeUtils.
Can anybody help me figure out what is wrong with the math here? I'm not sure what's causing the issue. Thank you very much for the help!
Here's the MazeRunner file:




And here's the MazeUtils file:

 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you've got a class variable a and an array location both initialized to zero, so when you get here:

location[a] = location[0] = 0. Then you subtract one and your array is out of bounds. Not sure why you get a NPE, but that's probably part of your problem.
 
Carey Brown
Bartender
Posts: 2996
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are not assigning any thing to 'map'. I assume that for

you really wanted
 
Liutauras Vilda
Marshal
Posts: 4649
318
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Liam Mass wrote:
Shouldn't be other way round? location = startPosition1
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!