This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Android and the fly likes The application has stopped unexpectedly. Please try again. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "The application has stopped unexpectedly. Please try again." Watch "The application has stopped unexpectedly. Please try again." New topic

The application has stopped unexpectedly. Please try again.

Dodge Worthington

Joined: May 11, 2010
Posts: 3

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.



Monu Tripathi

Joined: Oct 12, 2008
Posts: 1369

Can you filter your Logcat messages on Error and post only relevant stack dump?

[List of FAQs] | [Android FAQ] | [Samuh Varta]
Dodge Worthington

Joined: May 11, 2010
Posts: 3
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.


Dodge Worthington

Joined: May 11, 2010
Posts: 3
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);

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.

Shawn Franks

Joined: May 18, 2010
Posts: 23
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:

I agree. Here's the link:
subject: The application has stopped unexpectedly. Please try again.