Android Tech Help – How to Troubleshoot “The Application has Stopped Unexpectedly”

08 Jun. 2015 Mobile App

Applications stopping unexpectedly is one of the many issues faced while developing android apps. It not only impacts the novice programmers but is also a major concern for professional android developers. This error happens more frequently if your app is running across different devices. For example, when you are using an app, it suddenly crashes with the message ‘unfortunately (app) has stopped’. Sometimes the message also shows up even when the app is not in use. This article helps you fix the issue – ”Unfortunately app has stopped”

google play store has stopped working - notification

Error Message – Application has Stopped Working

Problem

Your app crashes without any reason and you wonder why?

Solution

For Normal App Crash Errors:

First begin by viewing the app log in the Android IDE where the emulator shows what the app crash looks like.

application crash view in android emulator

Application Stopped Unexpectedly – Force Close Message

Next we will use logcat function for viewing AVD’s log by executing the below code:

adb remount
adb logcat

Error Log Example:

E/DatabaseUtils( 53): Writing exception to parcel
E/DatabaseUtils( 53): java.lang.SecurityException: Permission Denial: writing com.android.providers.settings.
E/DatabaseUtils( 53): at android.content.ContentProvider$Transport.enforceWritePermission(ContentProvider.
E/DatabaseUtils( 53): at android.content.ContentProvider$Transport.insert(ContentProvider.java:149)
E/DatabaseUtils( 53): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:140)
E/DatabaseUtils( 53): at android.os.Binder.execTransact(Binder.java:287)
E/DatabaseUtils( 53): at com.android.server.SystemServer.init1(Native Method)
E/DatabaseUtils( 53): at com.android.server.SystemServer.main(SystemServer.java:497)
E/DatabaseUtils( 53): at java.lang.reflect.Method.invokeNative(Native Method)
E/DatabaseUtils( 53): at java.lang.reflect.Method.invoke(Method.java:521)
E/DatabaseUtils( 53): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/DatabaseUtils( 53): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/DatabaseUtils( 53): at dalvik.system.NativeStart.main(Native Method)
D/AndroidRuntime( 430): Shutting down VM
W/dalvikvm( 430): threadid=3: thread exiting with uncaught exception (group=0x4001b188)

Here we are dealing with a permission issue, so the solution is to add the WRITE_SETTINGS permission to our AndroidManifest.xml file for the instance.

<manifest … >
<application … />
<uses-permission android:name=”android.permission.WRITE_SETTINGS” />
</manifest>

For App Crash Errors like: Null Pointer Exception the logcat output will look like:

I/ActivityManager( 53): Displayed activity com.android.launcher/.Launcher: 28640 ms (total 28640 ms)
I/ActivityManager( 53): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.I/ActivityManager( 53): Start proc com.aschyiel.disp for activity com.aschyiel.disp/.Disp: pid=214 uid=10030 I/ARMAssembler( 53): generated scanline__00000177:03515104_00000001_00000000 [ 73 ipp] (95 ins) at [0x47c588:I/ARMAssembler( 53): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x47c708:I/ARMAssembler( 53): generated scanline__00000077:03010104_00000004_00000000 [ 22 ipp] (41 ins) at [0x47c818:D/AndroidRuntime( 214): Shutting down VM
W/dalvikvm( 214): threadid=3: thread exiting with uncaught exception (group=0x4001b188)
E/AndroidRuntime( 214): Uncaught handler: thread main exiting due to uncaught exception
E/AndroidRuntime( 214): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.aschyiel.disp/E/AndroidRuntime( 214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2496)
E/AndroidRuntime( 214): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
E/AndroidRuntime( 214): at android.app.ActivityThread.access$2200(ActivityThread.java:119)
E/AndroidRuntime( 214): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
E/AndroidRuntime( 214): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 214): at android.os.Looper.loop(Looper.java:123)
E/AndroidRuntime( 214): at android.app.ActivityThread.main(ActivityThread.java:4363)
E/AndroidRuntime( 214): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 214): at java.lang.reflect.Method.invoke(Method.java:521)
E/AndroidRuntime( 214): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
E/AndroidRuntime( 214): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
E/AndroidRuntime( 214): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 214): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 214): at com.aschyiel.disp.Disp.onCreate(Disp.java:66)
E/AndroidRuntime( 214): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 214): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
E/AndroidRuntime( 214): … 11 more


We can solve the NullPointer issue by executing the below code:

import …
public class Disp extends Activity
{
private TextView foo;
@Override
public void onCreate( Bundle savedInstanceState )
{

foo.setText(“bar”);
}
}

The above code might fail as we’ve forgotten to use findViewById().
After adding the function, the code will be:

import …
public class Disp extends Activity
{
private TextView foo;
@Override
public void onCreate( Bundle savedInstanceState )
{

foo = (TextView) findViewById( R.id.id_foo );
foo.setText(“bar”);
}
}

With the above code, the error should be resolved.
If you still face an error apart from Null Pointer Exception and don’t know why your android application has stopped working then feel free to check the Google Group Page – Google I/O 2009 – Debugging Arts of the Ninja Masters

Are you currently facing challenges while testing your mobile application? Is time of delivery and quality a major concern for you?

Get a Free ConsultationTalk to our team to learn how we can help optimize Android Testing for your App.

 

Here are some resources that might come handy:

Follow Us
Subscribe to the Blog
Get a Free Consultation
Reach out to our team to get a free consultation for your next projectContact Us