我試圖從一個EditText獲取一個字符串並解析爲一個double。但是我得到一個錯誤。如何解析字符串加倍時解決此錯誤?
if(controle == null || controle.trim() == "" || !controle.matches("\d+\.\d+|\d+")).
類似:
09-26 10:42:41.589: E/AndroidRuntime(17901): FATAL EXCEPTION: main
09-26 10:42:41.589: E/AndroidRuntime(17901): java.lang.NumberFormatException:
09-26 10:42:41.589: E/AndroidRuntime(17901): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
09-26 10:42:41.589: E/AndroidRuntime(17901): at java.lang.Double.parseDouble(Double.java:318)
09-26 10:42:41.589: E/AndroidRuntime(17901): at br.com.going2.Checkincomercial.NovoCheckinActivity$4.onClick(NovoCheckinActivity.java:219)
代碼
String controle = "";
controle = etCustoNovoCheckin.getText().toString();
if(controle == null || controle == ""){
custo = 0.0;
} else {
custo = Double.parseDouble(controle);
}
丘斯托是float或double? –
@BrijeshPatel'double'否則'丘斯托= 0.0;'編譯錯誤 –
丘斯托加倍。 – Roland