java - JTable 中 SUM 所有数据为 NULL 的问题
问题描述
我正在使用 Java。我有各种数据JTable
。我希望对所有内容进行求和,但其中包含 NULL。
float sum_OverTime_C = 0;
for (int i = 0; i < jTable_3.getRowCount(); i++) {
sum_OverTime_C = sum_OverTime_C + Float.parseFloat(jTable_3.getValueAt(i, 1).toString());
}
jLabel_Total_OverTime.setText(Float.toString(sum_OverTime_C));
解决方案
您必须在求和之前检查该值是否null
为,例如:
if(jTable_3.getValueAt(i, 1) != null){
sum_OverTime_C += Float.parseFloat(jTable_3.getValueAt(i, 1).toString());
}
推荐阅读
- android - 来自 React Native 的 Android App Bundle:您上传的 APK 或 Android App Bundle 的某些文件的签名信息无效或缺失
- android - 为什么我的底部导航视图不显示任何标题或图标?
- python-3.x - 以下 ResNet50 分类模型中验证准确度为 0 的原因
- json - 在 http rest 中查询空值
- python - 删除未使用标签的更好方法。/ django taggit python
- c++ - 有效地查找连续元素的总和 - INOI 2015,问题 1
- r - 如何使用 tidyverse 进行行计算以动态创建列?
- python - 我可以从终端更改指定 python 生成文件的位置吗?
- typescript - 打字稿如何使用包中的类型
- django - 有没有办法在 djangoTutorial 的投票教程中将此 FBV 转换为 CBV?