Question

I apologize in advance if I'm breaking any stack overflow question rules, I tried making sure everything I was doing was allowed, but I might have missed something. This is my first time actually asking a question.

I just got done with a program that uses Dijkstra's algorithm to find the shortest time between one station to all the other stations. My program runs, but when I type in my starting and stopping point I get these errors:

I understand what the error is, I'm just not sure where it is happening.

An unhandled exception of type System.ArgumentOutOfRangeException occurred in mscorlib.dll

Additional information:

Index was out of range. Must be non-negative and less than the size of the collection.

I didn't want to bombard everyone with huge amounts of code.... So I'm putting a link to the dropbox location where I have it: https://www.dropbox.com/sh/z7an3eho1lkm1h9/_0bm5taT31

Again, I'm sorry if I missed a rule and I'm breaking it. Let me know if I am and I'll try to repost the question in a way that is appropriate.

Was it helpful?

Solution

With Visual Studio you can tell the debugger to break when an exception is thrown:

http://msdn.microsoft.com/en-us/library/d14azbfh.aspx

Using this technique you should be able to find the root cause.

OTHER TIPS

You have to add two condition in your code which is mentioned below.

 if(Subway.Count>0)
            shortest.Add(Subway[s2]);

 int mins=0;
             if(Subway.Count>0)
             mins = Subway[s2].cost;

your subway list is empty still you find it item from it show it will through the exception.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top