user2471152
user2471152

Reputation: 11

CRUD java code error

i have a problem with the following code and i've been struggling with it for over a week now. i'm sure it's a basic problem but i can't get anywhere with it..

i'm trying to create a very simple CRUD application that allows me to keep a list of assets. the code i'm struggling with is as follows;

private void displayResult(List resultList) {
    ArrayList<String> tableHeaders = new ArrayList<String>();
    ArrayList tableData = new ArrayList();
    tableHeaders.add("AssetNo"); 
    tableHeaders.add("Type");
    tableHeaders.add("SubType");
    tableHeaders.add("Supplier");

    for(Object o : resultList) {
        Asset asset = (Asset)o;
        ArrayList<Object> oneRow = new ArrayList<Object>();
        oneRow.add(asset.getAssetNo());
        oneRow.add(asset.getType());
        oneRow.add(asset.getSubType());
        oneRow.add(asset.getSupplier());
        tableData.add(oneRow);
    }

    jTable1.setModel(new DefaultTableModel(tableData, tableHeaders));
}

Netbeans 7.3 displays an error on the for(Object.. line and the jTable1.setMode1.. lines.

Could anyone point me in the right direction to fix these problems?

Thanks

Upvotes: 1

Views: 446

Answers (1)

arshajii
arshajii

Reputation: 129537

The DefaultTableModel constructor takes Vectors, not Lists.

As for the for-loop error, I bet you imported java.awt.List instead of java.util.List.

Upvotes: 5

Related Questions