1. Are you ready for the Galaxy S20? Here is everything we know so far!

Answered: java help for simple converter

Discussion in 'Android Development' started by xDroidApps, Oct 11, 2011.

  1. xDroidApps

    xDroidApps Lurker
    Thread Starter

    hi, i am making a simple converter to learn Droid app development but i am having a problem. Here is my code:

    the problem is if the user imputs nothing, the program force closes. i can fix that by setting the SetText value to "0", but then it makes it harder to enter a second value because the 0 is added to the end unless deleted. How can i solve this? I tried: if sDistance != "" then double parse else =0.0 but it didn't work.

    Thanks
     



    1. Download the Forums for Android™ app!


      Download

       
  2. dCoder

    dCoder Newbie

    try {
    dDistance = Double.parseDouble(sDistance);
    } catch (NumberFormatException e) {
    dDistance = 0.0;
    }
     
    xDroidApps likes this.
  3. xDroidApps

    xDroidApps Lurker
    Thread Starter

    Excellent! thanks, it worked
     
Loading...

Share This Page

Loading...