tags:

views:

109

answers:

3

I have a table which in the first column ,I have student's name.such as "Esfandyar Talebi","Arash Nouri" and the number of rows can be changed. and just 2 rows are filled from 4 rows.

the code that I have written:

       List<String> professorsName = new ArrayList<String>();
         for(int i=0;i<InformationTable.getRowCount();i++){
            professorsName.add((String) InformationTable.getValueAt(i, 0));
            System.out.println(professorsName.toString());

         }

but it will show these things in the console:

[Esfandyar Talebi]

[Esfandyar Talebi, Arash Nouri]

[Esfandyar Talebi, Arash Nouri, null]

[Esfandyar Talebi, Arash Nouri, null, null]

[Esfandyar Talebi, Arash Nouri, null, null, null]

[Esfandyar Talebi, Arash Nouri, null, null, null, null]

null

+1  A: 

Apparently your InformationTable.getValueAt(i, 0) returns null for certain values of i. You'll have to look at your TableModel

iWerner
+1  A: 

There are probably 6 rows in the InformationTable. You probably first have to check wether the cell has been filled with a name:

     List<String> professorsNames = new ArrayList<String>();
     for(int i=0;i<InformationTable.getRowCount();i++){
        String name = (String) InformationTable.getValueAt(i, 0);
        if (name != null && name.trim().length() != 0) {
            professorsNames.add(name);
            System.out.println("Adding: " + name);
        } else {
           System.out.println("Refusing: " + name);
        }
     }
     System.out.println("Found: " + professorsNames.toString());
extraneon
+1  A: 

There is nothing strange with the loop you posted... It runs as many times as the value InformationTable.getRowCount() method returns, which appears to be six. So the problem is likely on the InformationTable class, you may need to post it if you need further help.

migsho