0

I'm having to traverse a graph for an assignment at uni, and I'm having an issue when using a Set. I've got the algorithm written already but for some reason this seems to be holding it up. Currently, I'm receiving a NullPointerException on the first line of the following (according to BlueJ):

Set<String> neighboursNames = map.getNeighboursNames(v);
List<String> reachable = new ArrayList<String>(neighboursNames);

When the getNeighboursNames() method is returning a Set of Strings as the names of the neighbouring nodes. I have been instructed that this is the correct method to use, and the variable v is referring to the current name of the current node.

Could somebody please point out where I might have gone wrong because I really can't see it, or let me know if there's nothing wrong with this section and the issue must lie elsewhere in the code.

Any help on this is appreciated, I've tried several things so far without success.

2
  • v must be null; could you post when it got initialized? Commented Nov 15, 2012 at 22:59
  • String v = q.remove(); When q is a LinkedList containing the current node name as the only entry at this point. Commented Nov 15, 2012 at 23:05

1 Answer 1

1

Most likely your "map", when you call "map.getNeighborsNames(v)", is null, if you post the stacktrace, it will be easier for me to help.

Debug mode will be very helpful to find stuff like this :).

Sign up to request clarification or add additional context in comments.

1 Comment

Oh, according to BlueJ you are correct :p Aside from that, is the code okay? (assuming map wasn't null).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.