Re: [android-beginners] The application has stopped unexpectedly. Please try again.

2010-05-12 Thread T1000

[ 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.0. 
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


Re: [android-beginners] The application has stopped unexpectedly. Please try again.

2010-05-12 Thread TreKing
On Wed, May 12, 2010 at 11:08 AM, T1000 t1...@zando.dyndns.org wrote:

 What am I doing wrong?


Print out the values of the strings just before you try to convert them,
then the value of what you get.
Why are you using Float to get a double value?

-
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 
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


Re: [android-beginners] The application has stopped unexpectedly. Please try again.

2010-05-12 Thread T1000
I can't print out the strings after I try to convert them using 
either of these two routines because it crashes.


double satlon = Double.valueOf(SatLon_Str).doubleValue();
double satlon = Double.parseDouble();

(Using a Float before was sloppiness on my part. However, even when I 
use a Double it still crashes.)


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 = SatLon_Str:  + SatLon_Str +  Length: + 
SatLon_Str.length() + String.format( Converted: %.5f, satlon);

ResultText.setText(output);

Below is the output to the preceding code. When I enter 123, I get 
123.0. When I enter 123.0, I get 0.0.


SatLon_Str: 123 Length:3 Converted: 123.0
SatLon_Str: 123.0 Length:5 Converted: 0.0

At 09:28 AM 5/12/2010, you wrote:
On Wed, May 12, 2010 at 11:08 AM, T1000 
mailto:t1...@zando.dyndns.orgt1...@zando.dyndns.org wrote:

What am I doing wrong?


Print out the values of the strings just before you try to convert 
them, then the value of what you get.

Why are you using Float to get a double value?

-
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/trekinghttp://sites.google.com/site/rezmobileapps/treking

--
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/androidhttp://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=enhttp://groups.google.com/group/android-beginners?hl=en




--
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


Re: [android-beginners] The application has stopped unexpectedly. Please try again.

2010-05-12 Thread TreKing
On Wed, May 12, 2010 at 12:10 PM, T1000 t1...@zando.dyndns.org wrote:

 I can't print out the strings after I try to convert them using either of
 these two routines because it crashes.


Weirdness - have you tried putting a break point right before the
Double.parse(value) call and see the value of the string there? Don't do
trim() or any that Scanner stuff - it should not be necessary (assuming of
course the value is actually a double).

-
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 
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