Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at dacia.Principale.jButton10ActionPerformed(Principale.java:1204)
at dacia.Principale.access$500(Principale.java:44)
Code:Exception in thread "AWT-Eventqueue-0" java.lang.NullPointerException TreeMap
XSSFWorkbook wg= new XSSFWorkbook();
XSSFSheet sht=wg.createSheet();
TreeMap<String,Object[]> data= new TreeMap<>();
// data.put("-1",new Object[]){"chasis","marque","couleur","nom client","date d entree","date sortie","telephone","numero WW","position","mode paiment","gamme","version"});
data.put("-1",new Object[]{jTable2.getColumnName(0),jTable2.getColumnName(1),jTable2.getColumnName(2),jTable2.getColumnName(3),jTable2.getColumnName(4),jTable2.getColumnName(5),jTable2.getColumnName(6),jTable2.getColumnName(7),jTable2.getColumnName(8),jTable2.getColumnName(9),jTable2.getColumnName(10),jTable2.getColumnName(11)});
for(int i=0;i<jTable2.getRowCount();i++)
{
data.put(Integer.toString(i),new Object[]{jTable2.getValueAt(i,0).toString(),jTable2.getValueAt(i,1).toString(),jTable2.getValueAt(i,2).toString(),jTable2.getValueAt(i,3).toString(),jTable2.getValueAt(i,4).toString(),jTable2.getValueAt(i,5).toString(),jTable2.getValueAt(i,6).toString(),jTable2.getValueAt(i,7).toString(),jTable2.getValueAt(i,8).toString(),jTable2.getValueAt(i,9).toString(),jTable2.getValueAt(i,10).toString(),jTable2.getValueAt(i,11).toString()});
}
//write to excel
Set <String> ids=data.keySet();
XSSFRow row ;
int roow=0 ;
for (String st : ids)
{
row=sht.createRow(roow++);
Object[] values=data.get(st);
int cellId=0 ;
for(Object o : values)
{
Cell cell=row.createCell(cellId++);
cell.setCellValue(o.toString());
}
}
try {
//write to file
FileOutputStream fos= new FileOutputStream(new File("/home/elprincipe/Desktop/dacia.xls"));
wg.write(fos);
fos.flush();
fos.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Principale.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Principale.class.getName()).log(Level.SEVERE, null, ex);
}
Das Problem ist in:
data.put(Integer.toString(i),new Object[]{jTable2.getValueAt(i,0).toString(),jTable2.getValueAt(i,1).toString(),jTable2.getValueAt(i,2).toString(),jTable2.getValueAt(i,3).toString(),jTable2.getValueAt(i,4).toString(),jTable2.getValueAt(i,5).toString(),jTable2.getValueAt(i,6).toString(),jTable2.getValueAt(i,7).toString(),jTable2.getValueAt(i,8).toString(),jTable2.getValueAt(i,9).toString(),jTable2.getValueAt(i,10).toString(),jTable2.getValueAt(i,11).toString()});
Höchstwahrscheinlich gibt eine der Zellen 'null' zurück und Sie können '.toString() 'nicht aufrufen. –