Question

I have the following code

ArrayList<Integer> Analysis = new ArrayList<>();
ArrayList<Integer> designInitialBuild = new ArrayList<>();
ArrayList<Integer> Production = new ArrayList<>();
ArrayList<Integer> Strategy = new ArrayList<>();
ArrayList<Integer> Testing = new ArrayList<>();
System.out.println("jTableLength: " + jTable1.getRowCount());
for(int xn=0;xn==jTable1.getRowCount();xn++){
   System.out.println(jTable1.getModel().getValueAt(xn, 3).toString());
   switch(jTable1.getModel().getValueAt(xn, 3).toString()){      
      case "Analysis":
          Analysis.add(xn);
          break;
      case "Design & Initial Build":
          designInitialBuild.add(xn);
          break;
      case "Production":
          Production.add(xn);
          System.out.println("Production");
          break;
      case "Strategy":
          Strategy.add(xn);
          break;
      case "Testing":
          Testing.add(xn);
          break;
      default:
          System.out.println("I am Broken");
          break;
    } 
}
System.out.println(Production.size());

When I debug the code it shows that the variable xn has a value of -8, it never goes into the for loop and does the first "println" Before the loop where I did System.out.println("jTableLength: " + jTable1.getRowCount()); it displays 48..... i'm so very confused.

Était-ce utile?

La solution

The condition on your for loop is wrong. The for loop will only execute while the condition is true. Try less than:

for(int xn=0;xn < jTable1.getRowCount();xn++){

This way, the loop will keep executing if xn is less than the row count, and it will stop then xn reaches the row count.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top