Results 1 to 2 of 2
Thread: Problem with Array Use
- 06-02-2010, 04:27 AM #1
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
Problem with Array Use
Hello, I am new to java and i have been dealing with a project right now, however i am facing a problem for which i can't find the solution.
The problem is exactly at the last loop where I get an ArrayIndexOutOfBoundsJava Code:import java.util.ArrayList; import java.util.Random; public class Realization { private int[] inGoers; private int[] outGoers; private int[] Weights; private int[][] tableA; private int[] Marked; private int[] CoverageIn; private int[] CoverageOut; private int totalMin = 0; private int min = Integer.MAX_VALUE; private int minNode; private boolean marked = false; public Realization(ArrayList<String> Eiserxomena, ArrayList<String> Exerxomena, int[] Varh, int nodes) { int arcs = Eiserxomena.size(); inGoers = new int[arcs]; outGoers = new int[arcs]; Weights = new int[arcs]; tableA = new int[nodes][arcs]; Marked = new int[nodes]; CoverageIn = new int[nodes]; CoverageOut = new int[nodes]; Weights = Varh; for(int i=0;i<arcs;i++) { inGoers[i] = Integer.parseInt(Eiserxomena.get(i)); outGoers[i] = Integer.parseInt(Exerxomena.get(i)); } for(int i=0;i<nodes;i++) for(int j=0;j<arcs;j++) tableA[i][j] = 0; for(int i=0;i<nodes;i++) for(int j=0;j<arcs;j++) System.out.println(tableA[i][j]); for(int j=0;j<arcs;j++) { tableA[inGoers[j]][j] = -1; tableA[outGoers[j]][j] = 1; } }
error but i don't understand why. The unused objects are part of the next code lines but they don't have to do with the problem (I didn't write the remaining part of the code to make things simpler as it the problem)
- 06-02-2010, 02:45 PM #2
Senior Member
- Join Date
- Feb 2009
- Posts
- 303
- Rep Power
- 5
Break it down into something simpler and add Debug lines to figure out what exactly is going on.
Java Code:for (int j = 0; j < arcs; j ++) { System.out.println("J: " + j); int inGoer = inGoers[j]; System.out.println("inGoer: " + inGoer); int outGoer = outGoers[j]; System.out.println("outGoer: " + outGoer); tableA[inGoer][j] = -1; tableB[outGoer][j] = -1; }
Similar Threads
-
array problem
By jabo in forum New To JavaReplies: 2Last Post: 03-31-2010, 09:54 AM -
Array problem
By c3jcarmy in forum New To JavaReplies: 11Last Post: 03-11-2010, 02:45 AM -
Array problem
By binarzt in forum New To JavaReplies: 5Last Post: 02-14-2010, 09:01 AM -
array problem
By oceansdepth in forum New To JavaReplies: 3Last Post: 04-05-2008, 02:25 AM -
array problem
By wats in forum New To JavaReplies: 1Last Post: 12-12-2007, 07:08 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks