从JTable获取值时出错

时间:2015-07-26 11:33:52

标签: java swing jtable

我编写了从JTable获取值并获取该值进行计算。

//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); 
        }

       }

当我执行代码时显示空指针异常。

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)

此行显示空指针异常

 double icost =(double) tableSale.getModel().getValueAt(j,3); 

这里有什么错误?

0 个答案:

没有答案