本文介绍了在jTable中汇总一列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在尝试从jTable中的列中获取值时遇到问题并总结它们。这是我到目前为止的代码:
I am having a problem trying to get values from a column within a jTable and sum them up. This is the code I have so far:
public void saveTable(){
for(int i = 0; i < jTable2.getRowCount(); i++){
int total = 0;
int Amount = (int) jTable2.getValueAt(i, 5);
total = Amount+total;
System.out.println(total);
}
}
但是我一直得到ClassCastException错误:
However I keep getting ClassCastException Errors specifically:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at my.rcsv1.accounting.DraftInvoice.saveTable(DraftInvoice.java:851)
这是指代码行:
int Amount = (int) jTable2.getValueAt(i, 5);
我需要做些什么才能让它发挥作用?
What do I need to do in order to get this to work?
谢谢!
推荐答案
int Amount = Integer.parseInt(jTable2.getValueAt(i, 5)+"");
会做的事情
这篇关于在jTable中汇总一列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!