I have two EditText fields in an app. The first EditText is set up to accept strings, in my case a name:
EditText nameField = (EditText) findViewById(R.id.nameOfCustomer);
String name = nameField.getText().toString();
I have two EditText fields in an app. The first EditText is set up to accept strings, in my case a name:
EditText nameField = (EditText) findViewById(R.id.nameOfCustomer);
String name = nameField.getText().toString();
I then added the following java code for the first EditText to check for nulls:
if(TextUtils.isEmpty(name))
{
Toast.makeText(this, "Please Enter Name ",Toast.LENGTH_LONG).show();
return;
}
This works just fine and when the TextUtils.isEmpty is true it causes the toast to display if no entry is made in the first EditText field.
The second EditText has the input type set to android:inputType="number" since I want to have the user enter a number only
I have duplicated this same code for the second EditText:
EditText nameField2 = (EditText) findViewById(R.id.ageOfPatient);
String name2 = nameField2.getText().toString();
and I check it for nulls before I parse to an integer:
if(TextUtils.isEmpty(name2)){
Toast.makeText(this, "Please Enter Patient Age ",Toast.LENGTH_SHORT).show();
return;
}
int val = Integer.parseInt( nameField2.getText().toString() );
However, it does not identify a null condition and causes the application to crash. I could not find anything that works.
Any suggestions would be most apprecited !
I then added the following java code for the first EditText to check for nulls:
if(TextUtils.isEmpty(name)) {
Toast.makeText(this, "Please Enter Name ",Toast.LENGTH_LONG).show();
return;
}
This works just fine and when the TextUtils.isEmpty is true it causes the toast to display if no entry is made in the first EditText field.
The second EditText has the input type set to android:inputType="number" since I want to have the user enter a number only
I have duplicated this same code for the second EditText:
EditText nameField2 = (EditText) findViewById(R.id.ageOfPatient);
String name2 = nameField2.getText().toString();
and I check it for nulls before I parse to an integer:
if(TextUtils.isEmpty(name2)){
Toast.makeText(this, "Please Enter Patient Age ",Toast.LENGTH_SHORT).show();
return;
}
int val = Integer.parseInt( nameField2.getText().toString() );
However, it does not identify a null condition and causes the application to crash. I could not find anything that works. Any suggestions would be most apprecited !