COMP 1406/1006 Tutorial 5 Tips
- You haven't studied recursion in class yet. Look up the course notes, google about recursion, and ask lots of questions.
- Recursion is a concept that a lot of students don't get immediately. If you're still confused by it at the end of the tutorial, don't worry too much about it, just make sure you read over the course notes at home and maybe try to get some more practice.
- If you're stuck, try writing out what you think the program should do in plain English, then see if you can write the code to match it, or ask someone near you if what you have makes sense.
- If you are getting a
NullPointerException (this will look like a really long error message)
- Find the line # in your code where the error occurred. This will be shown at the top of the error message. (You can click on it to go automatically to that line.)
- The line where the error occured will probably have code something like
aCell.visted()). If your
object is null, then you can't call
function() on that (null) object. So before you do any function calls, make sure to check
if (object != null)
- If your program seems to lock up you probably have an infinite loop. Make sure that if you have a while loop that it actually is checking something new every time. The most common problem here is that you're checking
while (next != null) but not changing
next inside the loop.
- To check for all unvisited neighbours note that
aCell.getNextUnvisitedNeighbour() will return
null if there aren't any. You'll need to check for this. (It will never return a cell which has already been visited, so you don't need to check that.)