The application … (process …) has stopped unexpectedly. Please try again

This Bug Solved on Mon June 20, 2011

I am writing my first Andoid application. And facing an error .. I consider it too strange but also expecting to face a lot of strange errors and bugs.

I googled to find out what cause that error. And tried to learn how to debug Android application on Eclipse but no luck.

The application I am writing is having only an image and button. The button is to switch the mobile from normal mode to silent mode and the reverse and the image is an indicator the for which mode currently is active.

When I got the error I highlighted all the the code and started unhighlighting one by one, till I found the this line specifically cause the error:

int ringerMode = mAudioManager.getRingerMode();

when I run the application, on the Debug prespective view , in the error log tab I am getting :

Android Debug

here is a text copy of that error:

No command output when running: ‘am start -n
ModelToggleActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’ on device emulator-5554
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=
Framework arguments:  -keyring /Users/ameen/.eclipse_key...
Command-line arguments:  -os macosx -ws cocoa -arch x86
-keyring /Users/ameen/.eclipse_keyring -showlocation

and here is all the code :

Android Bug

all other functions are highlighted.

I feel that something is missing in my development environment. Please I need help

I uploaded the zipped project folder into my DropBox folder if someone iterested to test it:

UPDATE – Mon June 20, 2011

The bug above is solved be a huge help from Mr. Greg Krimer (thank you) .. see details

He mentioned DDMS in hes message. DDMS (as I learned) is a way to debug your Android application in Eclipse. You can read learn it and read more about it from here.


DDMS screenshot

The brief of bug reason as Mr Greg wrote:

As you can see, the cause of the problem is just a NullPointerException on line 22 of your activity owing to the fact that mAudioManager is used before it is unitialized. You initialize it on line 28.

So, I was having this line in my code:

int ringerMode = mAudioManager.getRingerMode();

and just by modified it to:

mAudioManager = (AudioManager)getSystemService(AUDIO_SERVICE);

int ringerMode = mAudioManager.getRingerMode();

it works fine 🙂 .. I am so happy


One Response to The application … (process …) has stopped unexpectedly. Please try again

  1. Pingback: traiteur rabat

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: