2017-04-08 119 views
-3

我不明白我的程序何時讀取我的yml文件,它讀取float的類型,但它返回零或0.0。我有我的浮動TRIG_EDGE_LEV返回0.0,但它應該返回1.5。java:返回null或0.0

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

請構建[最少測試用例(HTTP ://stackoverflow.com/help/mcve),並將輸出**直接發佈到你的問題:) –

回答

0

解決您的問題 - 使用double代替float - 某處Jyaml的代碼庫裏面嘗試匹配浮點數來double型反思的getter/setter方法(不域)。由於你的領域是float型,基於反射匹配失敗,你會得到的0.0F

默認值在一個側面說明:

  • 字段和方法,即使用盒裝/對象版本 - Double而不是double。對於存在檢查,null比0.0更有意義。 (我也推薦java 8的Optional)。
  • Jyaml超級老,它的代碼庫看起來很可怕,請考慮使用更新的替代方法來進行yaml解析,最好是使用類似Jackson之類的註釋。
  • 傑克遜 - 使用註釋,因爲它們映射在YAML文件名,並根據Java約定保持代碼(字段和方法應該是駱駝套管)