NumberFormatException Error

前端 未结 5 1516
被撕碎了的回忆
被撕碎了的回忆 2020-12-11 08:48

the code is:

editText2=(EditText) findViewById(R.id.editText2);
editText3=(EditText) findViewById(R.id.editText3);
float from_value= Float.parseFloat(editTe         


        
5条回答
  •  臣服心动
    2020-12-11 08:59

    to me the best way is to do it like this:

    editText2=(EditText) findViewById(R.id.editText2);
    editText3=(EditText) findViewById(R.id.editText3);
    
    if(!editText2.getText().toString().matches("")){
    float from_value= Float.parseFloat(editText2.getText().toString());
    editText3.setText(" "+(from_value * 100.0));
    }
    

    And also add this line to your xml for editText2

    android:inputType="numberDecimal"
    

    Hope it helps !

提交回复
热议问题