Hey guys I am doing a Database Manager proyect and I am not able to display all the data that I get from a db on a JTable. The code is the following:
private Collection<Map<String, String>> allData;
private void refresh()
{
while(tableModel.getRowCount() > 0)
{
tableModel.removeRow(0);
}
try
{
allData = manager.get((String) DatabaseJList.getInstance().getSelectedObject()).getDataManager().getAllFieldsValues();
//This works fine, I have prove to print allData value and it is correct
Object[] rowToAdd = new Object[manager.get((String) DatabaseJList.getInstance().getSelectedObject()).getDataManager().getColumnNumber()];
//I create a Object[] with the number of colums size,works fine too
ArrayList<String> rowx = new ArrayList<String>();
for (Map<String, String> rowz: allData)
{
rowx = (ArrayList<String>) rowz.values();
int i = 0;
for (String str : rowx)
{
rowToAdd[i] = str;
}
}
tableModel.addRow(rowToAdd);
}
My idea is to use the method refresh at the beginning to load all the table data, and to call it again after insert,delete,modify to refresh the data but I get this error here:
java.uti.HashMap$Values cannot be cast to java.util.ArrayList
As I know the method .values() returns a Collection so don’t know where is the problem here.
Thanks a lot for the help guys.
Why does
rowxneed to be of typeArrayList<String>? Can’t you just declare it asCollection<String>?