How to get data from a JTable?
I know this answer is a bit late, but it is actually a very easy problem to solve. Your code gives an error when reading the entry because there is no entry in the table itself for the code to read. Populate the table and run your code again. The problem could have been solved earlier but from the code you posted it was not obvious what was inside your table.
It is best if you could post SSCCE that shows model initialization and its population with data. Also include details of the exception as there could be multiple sources for the problem.
Here is a demo based on @CedricReichenbach correction:
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.DefaultTableModel;
public class TestModel {
public static void main(String s[]) {
DefaultTableModel model = new javax.swing.table.DefaultTableModel();
model.addColumn("Col1");
model.addColumn("Col2");
model.addRow(new Object[]{"1", "v2"});
model.addRow(new Object[]{"2", "v2"});
List<String> numdata = new ArrayList<String>();
for (int count = 0; count < model.getRowCount(); count++){
numdata.add(model.getValueAt(count, 0).toString());
}
System.out.println(numdata);
}
}
The result is:
[1, 2]
I don't know those classes well, but I would guess you'll have to count from zero:
for (int count = 0; count < model.getRowCount(); count++){
numdata.add(model.getValueAt(count, 0).toString());
}
In Java, it is usual to count from 0 (like in most C-like languages)...