java:返回null或0.0

时间:2017-04-08 09:42:22

标签: java

我不明白,当我的程序读取我的yml文件时,它会读取float的类型,但它返回零或0.0。我的浮动TRIG_EDGE_LEV返回0.0但它返回1.5。

public class Loadyml {

  //static OscilloDSO1072B dso1072B = new OscilloDSO1072B("visa://192.168.53.67/USB0::0x0957::0x0588::CN55040484::INSTR") ;

private String TRIG_EDGE_SLOP;
private String ENABLE_CHAN_OFFSET;
private float TRIG_EDGE_LEV;
private String TIM_MODE;
private String SCALE_NUMBER;
private String TIM_MAIN_SCAL;
private String SCALE_CHAN;
private String TRIG_EDGE_SOURCE;
private String WAV_SOUR;
private String PROB_CHAN;
private String INVERSE_CHAN;
private String WAV_POINT_MODE;
private String DISPLAY_CHAN;
private String ENABLE_CHAN_BWL_OFF;
private String COUPLING_CHAN;
private String OFFSET_NUMBER;
private String WAV_FORM;

public String getTRIG_EDGE_SLOP() {
    return TRIG_EDGE_SLOP;
}
public void setTRIG_EDGE_SLOP(String TRIG_EDGE_SLOP) {
    this.TRIG_EDGE_SLOP = TRIG_EDGE_SLOP;
}
public String getENABLE_CHAN_OFFSET() {
    return ENABLE_CHAN_OFFSET;
}
public void setENABLE_CHAN_OFFSET(String ENABLE_CHAN_OFFSET) {
    this.ENABLE_CHAN_OFFSET = ENABLE_CHAN_OFFSET;
}
public float getTRIG_EDGE_LEV() {
    return TRIG_EDGE_LEV;
}
public void setTRIG_EDGE_LEV(float TRIG_EDGE_LEV) {
    this.TRIG_EDGE_LEV = TRIG_EDGE_LEV;
}
public String getTIM_MODE() {
    return TIM_MODE;
}
public void setTIM_MODE(String TIM_MODE) {
    this.TIM_MODE = TIM_MODE;
}
public String getSCALE_NUMBER() {
    return SCALE_NUMBER;
}
public void setSCALE_NUMBER(String SCALE_NUMBER) {
    this.SCALE_NUMBER = SCALE_NUMBER;
}
public String getTIM_MAIN_SCAL() {
    return TIM_MAIN_SCAL;
}
public void setTIM_MAIN_SCAL(String TIM_MAIN_SCAL) {
    this.TIM_MAIN_SCAL = TIM_MAIN_SCAL;
}
public String getSCALE_CHAN() {
    return SCALE_CHAN;
}
public void setSCALE_CHAN(String SCALE_CHAN) {
    this.SCALE_CHAN = SCALE_CHAN;
}
public String getTRIG_EDGE_SOURCE() {
    return TRIG_EDGE_SOURCE;
}
public void setTRIG_EDGE_SOURCE(String TRIG_EDGE_SOURCE) {
    this.TRIG_EDGE_SOURCE = TRIG_EDGE_SOURCE;
}
public String getWAV_SOUR() {
    return WAV_SOUR;
}
public void setWAV_SOUR(String WAV_SOUR) {
    this.WAV_SOUR = WAV_SOUR;
}
public String getPROB_CHAN() {
    return PROB_CHAN;
}
public void setPROB_CHAN(String PROB_CHAN) {
    this.PROB_CHAN = PROB_CHAN;
}
public String getINVERSE_CHAN() {
    return INVERSE_CHAN;
}
public void setINVERSE_CHAN(String INVERSE_CHAN) {
    this.INVERSE_CHAN = INVERSE_CHAN;
}
public String getWAV_POINT_MODE() {
    return WAV_POINT_MODE;
}
public void setWAV_POINT_MODE(String WAV_POINT_MODE) {
    this.WAV_POINT_MODE = WAV_POINT_MODE;
}
public String getDISPLAY_CHAN() {
    return DISPLAY_CHAN;
}
public void setDISPLAY_CHAN(String DISPLAY_CHAN) {
    this.DISPLAY_CHAN = DISPLAY_CHAN;
}
public String getENABLE_CHAN_BWL_OFF() {
    return ENABLE_CHAN_BWL_OFF;
}
public void setENABLE_CHAN_BWL_OFF(String ENABLE_CHAN_BWL_OFF) {
    this.ENABLE_CHAN_BWL_OFF = ENABLE_CHAN_BWL_OFF;
}
public String getCOUPLING_CHAN() {
    return COUPLING_CHAN;
}
public void setCOUPLING_CHAN(String COUPLING_CHAN) {
    this.COUPLING_CHAN = COUPLING_CHAN;
}
public String getOFFSET_NUMBER() {
    return OFFSET_NUMBER;
}
public void setOFFSET_NUMBER(String OFFSET_NUMBER) {
    this.OFFSET_NUMBER = OFFSET_NUMBER;
}
public String getWAV_FORM() {
    return WAV_FORM;
}
public void setWAV_FORM(String WAV_FORM) {
    this.WAV_FORM = WAV_FORM;
}


public void Loadfichier() throws FileNotFoundException{
    try {
        System.out.println(Yaml.loadType(new File("config.yml"), Loadyml.class));   
     } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 
}

    public String toString() {
    //dso1072B.setchanconftest(commande);
   // Float.parseFloat(SCALE_NUMBER);
    return "[Commande SCPI='"+WAV_FORM+","+ENABLE_CHAN_BWL_OFF+""
            + ","+TRIG_EDGE_LEV+","+TIM_MODE+""
            + ","+SCALE_NUMBER+","+TRIG_EDGE_SLOP+""
            + ","+DISPLAY_CHAN+","+TIM_MAIN_SCAL+""
            + ","+SCALE_CHAN+","+TRIG_EDGE_SOURCE+""
            + ","+WAV_SOUR+","+INVERSE_CHAN+""
            + ","+PROB_CHAN+","+WAV_POINT_MODE+""
            + ","+ENABLE_CHAN_OFFSET+","+COUPLING_CHAN+""
            + ","+OFFSET_NUMBER+"']";

  }
}

我该如何解决?

Console screen

1 个答案:

答案 0 :(得分:0)

要解决您的问题 - 请使用RuntimeError: wrapped C/C++ object of type QLabel has been deleted 代替double - 在Jyaml代码库中的某处,它会尝试将浮点数与 getter / setter方法(非字段)匹配反复键入float。由于您的字段属于double类型,因此基于反射的匹配失败,您将获得默认值0.0f

旁注:

  • 使用字段和方法的盒装/对象版本,即 - float代替Double。对于存在性检查,null比0.0更有意义。 (我也推荐java 8的double)。
  • Jyaml超级老,其代码库看起来很可怕,请考虑使用更新的yaml解析替代方法,最好使用Jackson之类的注释。
  • 使用Jackson - 使用注释按原样映射yaml文件中的名称,并根据java约定保留代码(字段和方法应该是驼峰式的)