I'm new to Xamarin. I am making an application that requires two editbox to receive numbers. when I click the button without typing anything in the editbox it crashes and exits. Can anyone help me with this. If someone does not type anything then appear on the screen to enter correct
Hi @Travisjoys ,
If you're using the Field (EditText) value, you should inevitably fill it with some value or make a test if the value is null or empty
Example :
1. Code causes your issue :public void Your_EditText_Clicked(object sender, EventArgs e) { if (Your_EditText.text.ToString() == "Travisjoys") { // code code code code code code ... } }
public void Your_EditText_Clicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(Your_EditText.Text)) return; if (Your_EditText.text.ToString() == "Travisjoys") { // code code code code code code ... } }
Hope that helps,
Mabrouk.
Answers
I'd have to know more about what happens behind the scenes when the button is clicked. Can you provide your button click event/command code? I'm also not sure what you meant in your last sentence.
Hi @Travisjoys ,
If you're using the Field (EditText) value, you should inevitably fill it with some value or make a test if the value is null or empty
Example :
1. Code causes your issue :
public void Your_EditText_Clicked(object sender, EventArgs e) { if (Your_EditText.text.ToString() == "Travisjoys") { // code code code code code code ... } }
public void Your_EditText_Clicked(object sender, EventArgs e) { if (string.IsNullOrEmpty(Your_EditText.Text)) return; if (Your_EditText.text.ToString() == "Travisjoys") { // code code code code code code ... } }
Hope that helps,
Mabrouk.
Sorry @JBeck my native language is Portuguese so my english is not very good . Thank you @Mabrouk these solutions that you put was very useful
No problem @Marf183 sorry I didn't understand better. I'm glad @Mabrouk had the answer you needed.
The key is to balance defensive code and efficient production times. As a general thumb rule, sit on the side of not trusting what you're writing. Add checks on the data you're working with and test whatever you're able to. Assumptions will bite you in the end. It may seem like bloat initially, but every edge case you can imagine will end up happening at some point.