[ 05-12 01:05:47.570   227:0xe3 E/AndroidRuntime ]
java.lang.NumberFormatException:
at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
        at java.lang.Double.parseDouble(Double.java:285)
at com.example.helloandroid.HelloAndroid$1.onClick(HelloAndroid.java:61)
        at android.view.View.performClick(View.java:2364)
        at android.view.View.onTouchEvent(View.java:4179)
        at android.widget.TextView.onTouchEvent(TextView.java:6540)
        at android.view.View.dispatchTouchEvent(View.java:3709)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
        at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659) at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
        at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
        at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:123)
        at android.app.ActivityThread.main(ActivityThread.java:4363)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
        at dalvik.system.NativeStart.main(Native Method)

OK, you're right. It's crashing in paseDouble. Line 61 is
> double satlon = Double.parseDouble(SatLon_Str.trim());

So I wrote this code to check that the string is a double, and if so, convert the string to a double:

String SatLon_Str = satlonEditText.getText().toString();
Double doubleValue = 0.0;
Scanner scanner = new Scanner(SatLon_Str);
while (scanner.hasNextDouble())
{
    doubleValue = scanner.nextDouble();
}
double satlon = doubleValue;
String output = String.format("satlon: %.5f", satlon);
ResultText.setText(output);

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 = Float.valueOf(SatLon_Str).floatValue();
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.

At 12:57 AM 5/12/2010, you wrote:
> 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:

> String SatLon_Str = satlonEditText.getText().toString();
> String GPSLat_Str = gpslatEditText.getText().toString();
> String GPSLon_Str = gpslonEditText.getText().toString();
> String MagVar_Str = magvarEditText.getText().toString();

Unless the problem is that the getText() method is returning null (which it could be) the problem is not going to be with these lines... You aren't doing anything here that would cause a problem.

It is far more likely that your problem lies with this code since you are not doing any sort of check for whether or not the string value can actually be parsed to a double:

> double satlon = Double.parseDouble(SatLon_Str.trim());
> double gpslat = Double.parseDouble(GPSLat_Str.trim());
> double gpslon = Double.parseDouble(GPSLon_Str.trim());
> double magvar = Double.parseDouble(MagVar_Str.trim());

> I ran the debugger, and I don't understand it's cryptic output.
Try looking at the LogCat output instead... it should tell you on exactly what line you are having the problem.

----------------------------------------------------------------------
There are only 10 types of people in the world...
Those who know binary and those who don't.
----------------------------------------------------------------------




--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to