This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I am trying to write a very simple Android app. It takes in four floating point numbers, does a calculation, and outputs three
floating point results. When I run my app, it crashes with this error:
The application Hello, Android (process com.example.helloandroid) has stopped unexpectedly. Please try again.
However, if I enter integers instead of floating point numbers, my program doesn't crash and does the correct calculation.
I have isolated the problem to these lines:
My program also works if I hard code in floating point numbers for the string variables even though it crashes if I type in
the very same numbers.
I ran the debugger, and I don't understand it's cryptic output. Also, nowhere does it list any exceptions related to my code.
Here is my code and the output from the debugger. By the way, it is calle HelloAndroid because I started with the HelloAndroid example
and built my app from there. Any help is greatly appreciated. Thanks.
Now when I enter a floating point number, it outputs 0.00000. Entering an integer works. My program doesn't crash anymore, but it still doesn't convert a string with a floating point number into a double.
This is my third attempt at converting a string to a double, all have failed. Here's what else doesn't work:
double satlon = Double.valueOf(SatLon_Str).doubleValue();
double satlon = Double.parseDouble(SatLon_Str.trim());
What am I doing wrong? All three of these routines work fine using the Sun JDK. Please help! Thanks.
I have noticed issues like this in the past with android. It tends not to like to convert a string to a number along with another method. I would suggest using the trim() method and then parse the double.