Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null Pointer Exception

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dijkstra algorithm:
What changes should i make?



output:
run:
vertices map {1=A, 2=B, 3=C, 4=D, 5=E}
Exception in thread "main" java.lang.NullPointerException
adjacencyMap {E={D=1}, A={B=1, C=1}, B={D=1, A=1}, C={D=1, A=1}}
E
A
Q [B, C]
processed [A]
at simulation.Dijkstra.doDijkstra(Dijkstra.java:73)
at simulation.Dijkstra.<init>(Dijkstra.java:43)
at simulation.Dijkstra.main(Dijkstra.java:155)
Java Result: 1
BUILD SUCCESSFUL (total time: 2 seconds)


help please!
 
Rose Jac
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok. I figured it out. I forgot to add D's directadjacentnodes.
Thanks!
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suggest you put this code into a debugger. Most of them allow you to set a break for unhandled exception, set one for null pointer and see where the deref of the null is.

I don't know if you're truncating the information or what, but mostly java exceptions can/do produce stack traces, which include the line number of the line where the exception occurred.

You do not say whether you know what a null pointer exception is, or what attempts you have made to figure out your problem. I am not inclined to debug your program for you from scratch; this forum really does better with more specific questions than "what's wrong here?", though the worst of those don't even give the output.

Do you have/use eclipse, netbeans, or something similar? Do you have any way of stepping through your code?

rc
 
Run away! Run away! Here, take this tiny ad with you:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic