0

how to check my jtable if null pointer? my code is always null pointer and then can't export to xls. this my code

if (tbGudangSales.getValueAt(i, 5).toString().trim().length() == 0) {
                        status = "tidak ada penjualan";
                    } else{
                        status = tbGudangSales.getValueAt(i, 5).toString();
                    }

                    label = new Label(4, baris, status, bordertabel);
                    excelSheet.addCell(label);

this my error Error null pointer

this my value table Table

Steven Wiaji
  • 44
  • 1
  • 8

1 Answers1

0

All you need to do is to check if the value is null. For example:

Object value = tbGudangSales.getValueAt(i, 5);

if (value != null)
{
    if(value.toString().trim().isEmpty()) // instead checking the length "manually", you can use the isEmpty() method
    {
        status = "tidak ada penjualan";
    } 
    else
    {
        status = value.toString();
    }
}
kAliert
  • 768
  • 9
  • 21