Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

The application has stopped unexpectedly. Please try again.

 
Dodge Worthington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

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.

HelloAndroid.java:

Main.xml:

Console:

Debugger:
 
Monu Tripathi
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you filter your Logcat messages on Error and post only relevant stack dump?
 
Dodge Worthington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Based on the time, only the last 15 lines happened after it crashed. Only 2 of those 15 lines start with ERROR. So here are the 2 lines:



Is that what you wanted? Am I doing something wrong as far as the debugger is concerned? How do I get a relevant stack dump? Please bear with me as I am unfamiliar with Java, Eclipse, and Android.

Thanks,

Dodge
 
Dodge Worthington
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's the logcat output:



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 and output the result:

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

Dodge
 
Shawn Franks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

So instead of this:



Try something like this:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic