0

VCID と VCIDBACKUP の null 値を "Dont Have" に置き換えようとしています。これが私のコードです:

if (controladorExcel == false) { 
            WritableWorkbook workbookVazio = Workbook.createWorkbook(file);


            WritableSheet sheet1 = workbookVazio.createSheet("First Sheet", 0);
            TableModel model = table.getModel();

            for (int i = 0; i < model.getColumnCount(); i++) {
                Label column = new Label(i, 0, model.getColumnName(i));
                sheet1.addCell(column);
                System.out.println(column.getContents());
            }
            int j = 0;
            for (int i = 0; i < model.getRowCount(); i++) {
                for (j = 0; j < model.getColumnCount(); j++) {
                    System.out.println(model.getRowCount());
                    System.out.println(model.getColumnCount());
                    if(model.getValueAt(i, j) == null){ //At this point I verify if the value is null
                        model.setValueAt("Nao possui", i, j);
                    }

                    Label row = new Label(j, i + 1, //I got NULL POINTER here
                            model.getValueAt(i, j).toString());
                    System.out.println(row.getContents());
                    sheet1.addCell(row);

                }
            }
            workbookVazio.write();
            workbookVazio.close();

これが私のAbstractTableModelのコードです:

public class MacroTableModel extends AbstractTableModel {

private String[] colunas;
private List<Macro> linhas;

public MacroTableModel(List<Macro> lista){
    this.colunas = new String[]{"VPN Name", "VCID", "VCID BACKUP"};
    this.linhas = new ArrayList<Macro>(lista);
}

public String getColumnName(int index) {
    return colunas[index];
}


public int getRowCount(){
    return linhas.size();
}

public int getColumnCount(){
    return colunas.length;
}


@Override
public void setValueAt(Object aValue, int rowIndex, int columnIndex){
    Macro macro = new Macro();
        switch(columnIndex){
            case 0:
                macro.setVpnName(aValue.toString());
                break;
            case 1:
                macro.setVcid(aValue.toString());
                break;
            case 2:
                macro.setVcid_BackUp(aValue.toString());
                break;
        }
   fireTableCellUpdated(rowIndex,columnIndex);
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
    Macro macro = linhas.get(rowIndex);
    switch(columnIndex){
        case 0:
           return macro.getVpnName();
        case 1:
            return macro.getVcid();
        case 2:
            return macro.getVcid_BackUp();
    }
    return null; 
}



public void setColunas(String[] colunas) {
    this.colunas = colunas;
}

public String getColunas(int i) {
    return colunas[i];
}

}

setValueAt メソッドをデバッグすると、正しい値が得られますが、それでも同じエラーが発生します。AbstractModel クラスの実装を忘れている可能性がありますが、正確にはわかりません。誰か助けてくれませんか?

4

1 に答える 1