Why is my Android app force closing when I try to check if an EditText has a double
Posted
by user336861
on Stack Overflow
See other posts from Stack Overflow
or by user336861
Published on 2010-05-18T08:54:31Z
Indexed on
2010/05/18
9:00 UTC
Read the original article
Hit count: 200
Scanner scanner = new Scanner(lapsPerMile_st);
if (!scanner.hasNextDouble()) {
Context context = getApplicationContext();
String msg = "Please Enter Digits and Decmials Only";
int duration = Toast.LENGTH_LONG;
Toast.makeText(context, msg, duration).show();
lapsPerMileEditText.setText("");
return;
} else {
//Edit box has only digits, Set data and display stats
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()));
}
<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 such as 3.4 or 5.8 it force closes. I cant seem to figure out whats going on. Any ideas?
Thanks
© Stack Overflow or respective owner