Text after "
scanner scanner = new scanner (lapsPerMile_st); If (! Scanner.hasNextDouble ()) {reference reference = getApplicationContext (); String msg = "Enter digits and Decmials only"; Int Period = Toast. LENNHH_LOG; Toast. Make text (context, message, duration). Show (); LapsPerMileEditText.setText (""); Return; } Else {// in the edit box, only digits, set data and performance statistics are data.setLapsPerMile (Integer.parseInt (lapsPerMile_st)); LapsRunLabel.setVisibility (0); LapsRunTextView.setText (Integer.toString (data.getLapsRun ())); MilesRunLabel.setVisibility (0); MilesRunTextView.setText (Double.toString (data.getLapsRun) / data.getLapsPerMile ())); } & Lt; EditText: Android: id = "@ + id / mileCount" Android: layout_width = "100dp" Android: layout_height = "wrap_content" android: layout_marginTop = "110dp" Android: inputType = "numberDecimal" Android: maxLength = "4" /> ;
For some reason if I enter a non decimal number such as 3 or 5, it works fine, but when I enter a floating point like 3.4 or 5.8 Let's force it off. I could not understand what's going on. Any ideas
use the right type:? Integer.parseInt, Float.ParseFloat, ... and take the account you are using in Java then the pars fails one ouf you will get an exception. NumberFormatException
string int_string = "1"; Int data = 0; // Try the default value {data = Integer.parseInt (int_string); } Hold (NumberFormatException E) {// You are trying to parse and int with a string that is not int! }
Comments
Post a Comment