I\'m realy beginning to learn Java. When I run this code everything works fine till I leave my EditText boxes in the from empty and hit the run button. Then I get:
Another improvement:
String thisIsIt = new Double(tvSumIn).toString();
if(tvSumIn < 2){
noSum.setText(thisIsIt + " This is it ");
}else{
noSum.setText("This is else");
}
could be:
if(tvSumIn < 2){
noSum.setText(tvSumIn + " This is it ");
}else{
noSum.setText("This is else");
}
Then you don't have to create a useless String
This is a java question, not an android question.
You should handle the NumberFormat exception in your code. What happens if somebody enters "abc" into the text box? What do you want your app to do? You handle exceptions using try/catch blocks: http://tutorials.jenkov.com/java-exception-handling/basic-try-catch-finally.html
You might also want to check if noKids.getText().toString() is empty before trying to convert it. It might make sense for there to be a different feedback to the user if the string is "" vs if the string is "abc".
Extending on Vladmir's post (I cannot add a comment to that specific one)
you can have a short hand of that using the following two lines instead of the if/else block (? is the equivalent of if/else, when used in certain situations)
noKidsStr = noKids.getText().toString();
etKids = (noKidsStr == null || noKidsStr.isEmpty())?0.0:Double.parseDouble(noKids.getText().toString());