An app crashes whenever yes sir an unexpected leave caused by anunhandled exemption or signal. An app that is written using Java or Kotlincrashes if that throws an unhandled exception, stood for by theThrowable class. Anapp that is written penampilan native-code language crashes if there’s an unhandledsignal, sebagai as SIGSEGV, throughout its execution.

Anda sedang menonton: Cara mengatasi google play berhenti

When an application crashes, terminates the app's process and displays a dialogto allow the user know that the app has stopped, as displayed in ilustrasi 1.


Figure 1. An app crash on one maker

An app doesn’t should be untuk berlari in the foreground for it to crash. Any kind of appcomponent, even materials like transfer receivers or content providers thatare untuk berlari in the background, can reason an app to crash. This crashes areoften confusing for users since they menjadi not proactively engaging with your app.

If your application is experiencing crashes, you can use the guidance in this halaman todiagnose and fix the problem.

Detect the problem

You may not always know that your users space experiencing an inordinate number ofcrashes through your app. If you have currently published her app, vitalscan help make you aware of the problem. vitals vitals can membantu improve your app"s power by alerting you, via thePlayConsole, once your app is exhibiting extreme vitals considers crashes excessive when one app:

Exhibits at least one crash in at the very least 1.09% that its day-to-day sessions. Exhibits 2 or more crashes in at the very least 0.18% the its day-to-day sessions.

A daily session suku to a day in which your application was used.For info on how Google permainan collects vitals data, watch thePlay Console documentation.

After you discover that your app is enduring from too numerous crashes, thenext action is to diagnose them.

Diagnose the crashes

Solving crashes have the right to be difficult. However, if you can identify the root cause ofthe crash, most likely girlfriend can uncover a solution to it.

There room many situations that can cause a crash in her app. Some reasons areobvious, favor checking for a null value or empty string, however others space moresubtle, like lulus invalid debates to an api or even complex multithreadedinteractions.

Crashes ~ above produce a stack trace, i beg your pardon is a photo of the succession ofnested functions dubbed in your program up come the moment it crashed. Friend canview crash ridge traces vitals.

Reading a ridge trace

The first step to settle a crash is to identify the location where that happens. Girlfriend canuse the ridge trace available in the report details if friend are using PlayConsole or the calculation of the logcat tool. If youdon’t have a stack map available, friend should in your ar reproduce the crash,either by manually trial and error the application or by getting to out to influenced users, andreproduce it while penampilan logcat.

The complying with trace shows an example of a crash top top an application written lihat the Javaprogramming language:

--------- beginning of crashreactora.netRuntime: deadly EXCEPTION: mainProcess:, PID: 3686java.lang.NullPointerException: crash sampleat$1.onClick($ java.lang.reflect.Method.invoke(Native Method)at$ beginning of systemA stack trace mirrors two pieces of information that are an important to debugging acrash:

The kind of exemption thrown.The section of code wherein the exemption is thrown.

The form of exception thrown is commonly a very strong hint together to what wentwrong. Watch at even if it is it is anIOException, anOutOfMemoryError,or something else, and find the documentation around the exemption class.

The class, method, file, and line number of the source record where the exceptionis thrown is presented on the 2nd line the a ridge trace. For each role thatwas called, lainnya line shows the preceding call site (called a ridge frame).By walking up the ridge and evaluating the code, girlfriend may discover a ar that ispassing an incorrect value. If your code doesn’t show up in the stack trace, itis most likely that somewhere, you passed an invalid parameter right into an asynchronousoperation. You deserve to often malu out maafkan saya happened by analyzing each heat of thestack trace, detect any api classes the you used, and confirming the theparameters you passed were correct, and also that you called it native a ar that isallowed.

Stack traces for apps with C and C++ code work lot the very same way.

Tips because that reproducing a crash

It’s mungkin that friend can’t quite reproduce the problem hanya by starting anemulator or connecting your maker to her computer. Perkembangan environmentstend to have an ext resources, sebagai as bandwidth, memory, and storage. Use thetype of exemption to determine apa could it is in the resource that is scarce, orfind a correlation in between the version of, device type or her app’sversion.

Memory errors

If you have actually anOutOfMemoryError,then you mungkin create an emulator v low memory capacity to check with. Figure2 mirrors the AVD manager setups where you can control the lot of memory onthe device.


Figure 2. Memory setup on AVD manager

Networking exceptions

Since users commonly move in and also out of mobile or WiFi network coverage, in anapplication network exception usually should not be treated as errors, butrather as normal operating problems that occur unexpectedly.

If you must reproduce a network exception, seperti as anUnknownHostException,then shot turning on plane mode kapan your application attempts to usage thenetwork.

Another option is to minimize the top quality of the network in the emulator bychoosing a network rate emulation and/or a network delay. You can use theSpeed and Latency settings on AVD manager, or friend can mulai the emulatorwith the -netdelay and -netspeed flags, as shown in the followingcommand-line example:

emulator -avd -netdelay 20000 -netspeed gsmThis example sets a hold-up of 20 secs on every network requests and also an uploadand download rate of 14.4 Kbps. For more information ~ above command-line optionsfor the emulator, seeStart the emulator from the command line.

Reading with logcat

Once you space able have the actions to blee the crash, you deserve to use a alat likelogcat to get moreinformation.

The logcat calculation will display you what other log messages you have actually printed, alongwith others from the system. Nothing forget to revolve off any extraLog statements the youhave added because printing castle wastes CPU and battery while your application isrunning.

Prevent crashes led to by null reminder exceptions

Null reminder exceptions (identified through the runtime error typeNullPointerException) take place when you're do the efforts to access an object that isnull, commonly by invoking its methods or accessing the members. Null pointerexceptions room the largest cause of application crashes top top Google Play. The function ofnull is to represent that the object is absent - because that example, it hasn't beencreated or assigned yet. To prevent null tip exceptions, you must make surethat the object references you're working with are non-null before callingmethods on them or trying to access milik mereka members. If the object recommendation isnull, take care of this case well (for example, leave from a method sebelum performingany operations on the thing reference and also write info to a debug log).

Because girlfriend don't want to have null checks for every parameter of every methodcalled, you have the right to rely ~ above the ide ide or top top the kind of the thing to signifynullability.

Lihat lainnya: Surat Ke 18 Dalam Al Quran, Bacaan Surat Al Kahfi, Surat Ke

Java programming language

The following sections use to the Java programming language.

Compile time warnings

Annotate her methods' parameters and return values with