0

I'm trying to add int values to array list

ArrayList<Integer> arraylistPage1;

for(int j=1;j<=totalPage;j++){  
     int x=0;
     for(int i=1;i<=rangeMode;i++){
          if(binaryTable[i][j]==1){
             cardInPage[j][x]=i;
             System.out.println("card number: "+i);
             arraylistPage1.add(i);
             System.out.println(arraylistPage1);
             x++;                   
          }
     }
     System.out.println("page-"+j+" total card:"+x);
     totalCardInPage[j]=x;
}

But when I run it, the program just stops.

Does anyone know how to fix this?

Thanks

3
  • 1
    I recommend you step through it with a debugger to find out what's actually happening while it's "stopped". Commented Apr 22, 2014 at 8:16
  • What if totalPage == 0? Commented Apr 22, 2014 at 8:16
  • @Vakh the totalpage will never be 0 in this case Commented Apr 22, 2014 at 8:19

1 Answer 1

1

Change the code to this,

ArrayList<Integer> arraylistPage1;

for(int j=1;j<=totalPage;j++){  
 int x=0;
 arraylistPage1 = new ArrayList<Integer>(rangeMode);
 for(int i=1;i<=rangeMode;i++){
      if(binaryTable[i][j]==1){
         cardInPage[j][x]=i;
         System.out.println("card number: "+i);
         arraylistPage1.add(i);
         System.out.println(arraylistPage1);
         x++;                   
      }
 }
 System.out.println("page-"+j+" total card:"+x);
 totalCardInPage[j]=x;
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.