Results 1 to 5 of 5
- 04-05-2012, 12:16 AM #1
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Exception in thread "main" java.lang.StackOverflowError
Hello everyone! As the title says I am having a problem with my code. There error I am getting is:
Here is my code:Java Code:Exception in thread "main" java.lang.StackOverflowError at java.util.LinkedList.get(LinkedList.java:315) at probtest.prob.iterate(prob.java:66) at probtest.prob.iterate(prob.java:93) at probtest.prob.iterate(prob.java:88)
This is just one class and can provide others if needed, but do not think they will be needed. My question is what could be causing this and how do I fix it? Thanks!Java Code:import java.util.*; public class prob { public int probType; public String src; public LinkedList<String> dest; public Answer done; public prob(int num, String node1) { probType = num; src = node1; dest = new LinkedList<String>(); done = new Answer(src); } public prob(int num, String node1, LinkedList<String> node2) { probType = num; src = node1; dest = node2; done = new Answer(src); } public void solve(data_list d) { if (probType == 1) { String tempStr = dest.get(0); iterate(done, d, src, tempStr); } if (probType == 2) { LinkedList<String> temp1 = dest; iterate(done, d, src, temp1); } if (probType == 3) { LinkedList<String> temp2 = new LinkedList<String>(); for (int i = 0; i < d.num_nodes; i++) { temp2.add(d.cities[i]); } iterate(done, d, src, temp2); } done.printAnswer(); } public void iterate(Answer a, data_list d, String s1, String s2) { int len = d.list.size(); data temp; for (int i = 0; i < len; i++) { temp = d.list.get(i); if (s1.equals(temp.src) && s2.equals(temp.dest)) { a.add(temp.cost, temp.dest); if(done.total == 0 || a.total < done.total) { done = a; } return; } if (s2.equals(temp.src) && s1.equals(temp.dest)) { a.add(temp.cost, temp.src); if(done.total == 0 || a.total < done.total) { done = a; } return; } if (s1.equals(temp.src) && !s2.equals(temp.dest)) { a.add(temp.cost, temp.dest); iterate(a, d, temp.dest, s2); } if (s1.equals(temp.dest) && !s2.equals(temp.src)) { a.add(temp.cost, temp.src); iterate(a, d, temp.src, s2); } } } public void iterate(Answer a, data_list d, String s, LinkedList<String> lis) { LinkedList<String> l = new LinkedList<String>(); for ( int i = 0; i < lis.size(); i++ ) { l.add(lis.get(i)); } int len = d.list.size(); int len2 = l.size(); data temp; for (int i = 0; i < len; i++) { temp = d.list.get(i); for (int j = 0; j < len2; j++) { if (s.equals(temp.src) && l.get(j).equals(temp.dest)) { a.add(temp.cost, temp.dest); String prev = l.remove(j); if((done.total == 0 || a.total < done.total) && l.size() == 0) { done = a; return; } iterate(a, d, prev, l); len2 = l.size(); j--; continue; } if (temp.dest.equals(s) && temp.src.equals(l.get(j))) { a.add(temp.cost, temp.src); String prev = l.remove(j); if((done.total == 0 || a.total < done.total) && l.size() == 0) { done = a; return; } iterate(a, d, prev, l); len2 = l.size(); j--; continue; } if (temp.src.equals(s) && !temp.dest.equals(l.get(j))) { a.add(temp.cost, temp.dest); iterate(a, d, temp.dest, l); continue; } if (temp.dest.equals(s) && !temp.src.equals(l.get(j))) { a.add(temp.cost, temp.src); iterate(a, d, temp.src, l); continue; } } } } }
- 04-05-2012, 02:24 AM #2
Re: Exception in thread "main" java.lang.StackOverflowError
If you don't understand my response, don't ignore it, ask a question.
- 04-05-2012, 04:31 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 5
- Rep Power
- 0
Re: Exception in thread "main" java.lang.StackOverflowError
So what if it is cross posted? Is that against the rules? If more people spent time actually trying to help as opposed to criticizing a post, I would think more people such as myself, would be more inclined to help others.
Last edited by csharp100; 04-05-2012 at 04:34 AM.
- 04-05-2012, 07:15 AM #4
Re: Exception in thread "main" java.lang.StackOverflowError
Way to go, csharp100. Now you're going to have people falling over each other trying to help you. Not.
More to the point, where do you see criticism in Norm's post? I see a simple statement of fact. So all that your knee-jerk reaction proves is that you believe cross posting to be wrong, but went ahead and did it anyways.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
-
Re: Exception in thread "main" java.lang.StackOverflowError
Again, it's not criticism, it is warning to other volunteers here to check the cross-post so as not to waste time answering a question that's already been answered elsewhere. I don't know about you, but I value my free time, and I very much appreciate it if posters let us know up front that they've cross-posted and where they've done so because it shows that they have consideration for my time as well.
Similar Threads
-
Got struck with this :- " Exception in thread "main" java.lang.NullPointerException"
By Vermont in forum New To JavaReplies: 5Last Post: 12-21-2011, 06:44 PM -
Exception in thread "main" java.lang.StackOverflowError
By chris.bos in forum NetBeansReplies: 1Last Post: 12-02-2011, 06:55 PM -
Exception in thread "main" java.lang.NumberFormatException:input string: "060320
By renu in forum New To JavaReplies: 14Last Post: 04-08-2011, 06:01 PM -
Exception in thread "main" java.lang.StackOverflowError
By felito in forum New To JavaReplies: 4Last Post: 02-01-2011, 08:52 AM -
Question about error "Exception in thread "main" java.lang.NoSuchMethodError: main
By ferdzz in forum New To JavaReplies: 5Last Post: 06-22-2010, 03:51 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks