I coded for getting values from the JTable and get that value for do calculations.
//getting user input for selling qty
String Qty=JOptionPane.showInputDialog("Insert Selling Quantity :");
double sellingqty=Double.parseDouble(Qty);
//getting user input for specific item discount
String discount = JOptionPane.showInputDialog("Insert Item Discount");
double idiscount=Double.parseDouble(discount);
for(j=0;j<100;j++){
double icost =(double) tableSale.getModel().getValueAt(j,2);
System.out.print(icost);
//calculating Gross Total
double grosstotal = (sellingqty*icost)-idiscount;
System.out.println(grosstotal);
for(i=0;i<100;i++){
//setting qty input value to table sale
tableSale.getModel().setValueAt(sellingqty,i, 3);
//setting input value to table sale
tableSale.getModel().setValueAt(idiscount,i, 4);
//setting grosstotal value to table sale
tableSale.getModel().setValueAt(grosstotal,i, 5);
}
}
When I execute the code shows a null pointer exception.
java.lang.NullPointerException at
com.bit.project.Newsale.add_btnActionPerformed(Newsale.java: 710) at
com.bit.project.Newsale.access$800(Newsale.java: 37) at
com.bit.project.Newsale$12.actionPerformed(Newsale.java: 469) at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java: 2022) at
javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java: 2022) at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java: 2346)
This line shows the Null Pointer Exception
double icost =(double) tableSale.getModel().getValueAt(j,3);
What is the error here?