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 ameen.android.silentModeToggle/ameen.android.silentModeToggle.Silent-
ModelToggleActivity -a android.intent.action.MAIN -c android.intent.category.LAUNCHER’ on device emulator-5554

com.android.ddmlib.ShellCommandUnresponsiveException
	at com.android.ddmlib.AdbHelper.executeRemoteComm...
	at com.android.ddmlib.Device.executeShellCommand(...
	at com.android.ide.eclipse.adt.internal.launch.Ac...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
	at com.android.ide.eclipse.adt.internal.launch.An...
eclipse.buildId=M20110210-1200
java.version=1.6.0_24
java.vendor=Apple Inc.
BootLoader constants: OS=macosx, ARCH=x86, WS=cocoa, NL=
en_US
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:

http://www.4shared.com/file/owbZCn0m/Silent_Model_Toggle.html

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

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

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

%d bloggers like this: