基本上,假设我有两个这样的双值:
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;
public class UI {
public static void main(String args[]){
JSpinner stonesSpinnerImperial;
JSpinner poundsSpinnerImperial;
stonesSpinnerImperial = new JSpinner();
poundsSpinnerImperial = new JSpinner();
stonesSpinnerImperial.setModel(new SpinnerNumberModel(3, 3, 31, 1));
poundsSpinnerImperial.setModel(new SpinnerNumberModel(0.0, 0.0, 13.0, 1.0));
double imperial_stones = (double) stonesSpinnerImperial.getModel().getValue();
double imperial_pounds = (double) poundsSpinnerImperial.getModel().getValue();
double total_imperial_weight = imperial_stones + imperial_pounds;
}
}
但是我收到以下错误: java.lang.Integer cannot be cast to java.lang.Double
我觉得我背后的逻辑是有缺陷的,对此问题的任何帮助将不胜感激。
编辑:我已经添加了我认为需要的内容。