Java Graph Adjacency List error java.lang.NullPointerException...

I am creating an Graph using Adjacency Lists. However I am getting an error: Exception in thread "main" java.lang.NullPointerException. According to the error, it seems to be in the printGraph() function. at graph.Graph.printGraph(Graph.java:120) at graph.Graph.main(Graph.java:160) Someone was able... show more I am creating an Graph using Adjacency Lists. However I am getting an error:

Exception in thread "main" java.lang.NullPointerException.

According to the error, it seems to be in the printGraph() function.

at graph.Graph.printGraph(Graph.java:120)

at graph.Graph.main(Graph.java:160)

Someone was able to help me and suggested the "try-catch". This removed the error, however it seems my printGraph() function still doesn't work. I think I might have an error with creating an object but I do not know how to fix this. Thank you!


Link to code:
https://stackoverflow.com/questions/48899811/graph-adjacency-list-error-with-printgraph-function
3 answers 3