Results 1 to 2 of 2
  1. #1
    Mike90 is offline Member
    Join Date
    Apr 2010
    Posts
    1
    Rep Power
    0

    Default 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. #2
    StormyWaters is offline Senior Member
    Join Date
    Feb 2009
    Posts
    307
    Rep Power
    6

    Default

    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

  1. array problem
    By jabo in forum New To Java
    Replies: 2
    Last Post: 03-31-2010, 10:54 AM
  2. Array problem
    By c3jcarmy in forum New To Java
    Replies: 11
    Last Post: 03-11-2010, 03:45 AM
  3. Array problem
    By binarzt in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 10:01 AM
  4. array problem
    By oceansdepth in forum New To Java
    Replies: 3
    Last Post: 04-05-2008, 03:25 AM
  5. array problem
    By wats in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 08:08 AM

Posting Permissions

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