-5

I use intent to go to next activity.

            Intent intent = new Intent(g.currentActivity, Activity2.class);
            intent.putExtra("Name", edtNameInput);
            intent.putExtra("Family", edtFamilyInput);
            intent.putExtra("Age", edtAgeInput);
            g.currentActivity.startActivity(intent);

but when I leave the texts empty that I provided in the xml, the app crashed. How can I solve it? thank you.

This is the Logcat error.

https://i.stack.imgur.com/c6ygn.png

sajad
  • 1
  • 4

1 Answers1

0

The Logcat shows that the exception occurred when parsing Integer when the provided Integer is "". From the fields you are using, the integer is probably edtAgeInput.

The way you solve it depends from how you want to handle empty values. If you are getting the user input, what should happen if age is not provided/not available? (this depends from what you are trying to achieve) You could add a default value which will be used in case the fields are left empty. Alternatively, if the next activity is triggered by the user clicking a button you could only enable the button after all fields have values. Or, after user click the button, you can check the values and if they are not as expected, highlight the field and allow the user to correct before launching the next activity.

sigute
  • 1,143
  • 12
  • 21
  • thank you very much. It helps me a lot. bur I have a question. how can I do this : if the next activity is triggered by the user clicking a button you could only enable the button after all fields have values – sajad Feb 02 '15 at 21:32
  • take a look at this answer: http://stackoverflow.com/a/8225293/1615525 , it shows a code example on how you can achieve this. This is for one field, but in your method for checking whether all input is ready you could check all required fields, so you know that all conditions are met. – sigute Feb 02 '15 at 21:52