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.

Java 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;
}
}```
The problem is exactly at the last loop where I get an ArrayIndexOutOfBounds
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)

2. Senior Member
Join Date
Feb 2009
Posts
312
Rep Power
9
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;
}```

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•