I'm trying to populate a JTable
from an ArrayList
, The ArrayList
is filled with data from my database.
this is the code I tried :
DefaultTableModel model = new DefaultTableModel();
model.setColumnIdentifiers(new String[]{"Numéro d'ordre", "Article", "Quantité", "Remarque"});
for (gestionstock.LigneBonInterne o : listLigneBonInterne) {
model.addRow(new String[]{o.getNumOrder().toString(), o.getdesgArt(), o.getQte().toString(), o.getRemarque()});
System.out.println(o.toString());
}
jTable1.setModel(model);
But I get this error message :
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at magasinier.BonInterneDetails.(BonInterneDetails.java:63)
the ligne 63 is : jTable1.setModel(model);
I did a test to see if the ArrayList
is filled, and I found that the ArrayList
is filled with records which means that there is no problem with filling the ArrayList
How can I solve this problem ?
EDIT :
I tried to create the JTable
using code and assign it to ScrollPane
:
JTable jTable1 = new JTable(model);
jTable1.setModel(model);
jScrollPane1.setViewportView(jTable1);
But I still get the same error this time is the line : jScrollPane1.setViewportView(jTable1);