当输入的editText超过10位时,java应用程序停止
我试图显示calculation textView(txtHasil),它正在运行,但当输入超过10个应用程序时,突然强制关闭。这是我的代码:
btnHitung.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//String plafond = NumberTextWatcherForThousand.trimCommaOfString(edtPlafond.getText().toString());
String plafond = edtPlafond.getText().toString().trim();
String jasa = edtJasa.getText().toString().trim();
int edtPlafond = Integer.parseInt(plafond);
float edtJasa = Float.parseFloat(jasa);
double hasil = (edtPlafond * edtJasa )/100;
txtHasil.setText(""+hasil+"\nplafond: "+edtPlafond+"\nJasa: "+edtJasa);
//txtHasil.addTextChangedListener(new NumberTextWatcherForThousand((EditText) txtHasil));
}
}
我一直在尝试更改int、float和double。我已经读过这个链接:This program doesn't work properly for decimals more than 10 digits?但没有帮助。任何建议都会有帮助。谢谢
# 1 楼答案
这就是问题所在。它不能解析大于Integer.MAX_VALUE的任何东西
最好是有一个更长的价值-长
以及通过在对话框中显示错误,以更好的方式处理错误的示例:
注意:所有转换都需要这样的处理