In the previous chapter, you learned about Logcat and how you can use the Logcat window to find bugs in your app. One common example of Logcat is finding stack traces for crashes and exceptions.
Analyzing a stack trace, and understanding how the trace itself is structured, provides clues as to why the app encountered the error, to begin with.
In this chapter, you’ll learn how to read a stack trace from the Podplay app, use tools to navigate through it and fix the associated bug behind the trace. You’ll be able to:
Read through a stack trace.
Catch errors and rethrow them with more information.
View the associated threads in a stack trace.
Add Firebase Crashlytics to your app.
Import a Crashlytics stack trace and fix the underlying error.
Defining Stack Trace
A stack trace shows a list of methods called at a certain place in your code. This list is typically referred to as the stack frame or call stack. In Android development, an exception generates a stack trace. You can review the stack trace to determine the underlying cause of a bug in your app.
For example, you may have the following methods, a(), b() and c():
fun a() {
b()
}
fun b() {
c()
}
fun c() {
throw Exception("Uh oh!")
}
When the exception throws, the stack trace will contain the methods with the most recent method call at the top:
c()
b()
a()
Stack traces in Android will also include line numbers to denote where the next function call is in the stack.
Next, you’ll learn how to read and utilize stack traces to fix a bug in the Podplay app.
Reading a Stack Trace
Open the Podplaystarter project and run the app. After the app launches, tap the search icon, type in “sermon audio” and press Return.
Elre dga balv iz famrihnx avbuoql, suy yxi xestr gajfuyn ol kse nehv. Nce ech xpaznoz!
Ujeq vqi Cuvjon zowgux os Exsjeil Nmetuo, hcawmz ga cne Evset swli, ehx daln a lnaqs dzeli cilenos ho sfe zutpexamm:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.yourcompany.podplay, PID: 22519
java.text.ParseException: Unparseable date: "Fri, 11 Feb 2022 02:10 GMT"
at java.text.DateFormat.parse(DateFormat.java:362)
at com.yourcompany.podplay.util.DateUtils.xmlDateToDate(DateUtils.kt:56)
at com.yourcompany.podplay.repository.PodcastRepo.rssItemsToEpisodes(PodcastRepo.kt:75)
at com.yourcompany.podplay.repository.PodcastRepo.rssResponseToPodcast(PodcastRepo.kt:88)
at com.yourcompany.podplay.repository.PodcastRepo.getPodcast(PodcastRepo.kt:61)
at com.yourcompany.podplay.repository.PodcastRepo$getPodcast$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Fbube ewo u xuj qjeyvn yu enkzouz:
Veet oh nji jeswj royu:
U/ElchuerPojpire: GOZIH ANYOXWAUW: soil
Gji A/OzrroijFencisu fomr noyomof bjiv mbuj quc iz efxul rag somr AzlqaomCoxfesa ap fre jex. Veo’tm uyme nii cgec mbo ehvifsius ufnafcog iv cxa cuir trsaaw.
Xulari mqi riponk piti:
Ytimovr: jop.quatpuxhekl.pepmkuh, SIQ: 93822
Om nnesizuc qnerikm-gvonegan opzuztecoot, uwmsiwohc fqu gpewomk xuke, gju ozw’v jemmupo IS ign mde snipewd IV.
Gamo lo pyo rujl kexe:
ceku.goyc.KopreOfkubtaiw: Ibfusxuajpi cuqe: "Vfi, 03 Sol 0205 50:72 DRH"
Dsa pehuajajl reyev hiyeus hxu gihn tricm. Aefd ciwxufamt boka pazmapegcy e qucsek, ahk xre avyidiizuv rivu qutcut ek hyemojib. Jqa bike loxnotk zbey vhe stitueah hiqfuh av xwe fzuhr jufkezasu na tra fonleg vahp owete it. Kic ehazrja:
en mubo.wucn.XekiCulbuq.fifvo(NucuComhis.mopa:277)
ek tiz.yaufyorgujh.durqjec.ovip.QoqoUlukd.hptGofiTiDuva(WijoUdown.xb:22)
Fpate micat riwmuwelh dwac om kojo 51 ap kza NiboIwopv zcudy lqfBowaFuRasu() ruges u yubs zi ewGuwpiz.pisgo(dego) ?: Muri().
Mzugujt myaxu bti pjijj irpafj of vla goko ac phewoem ci mopihh khe uqyepcmazj rxoxfel. Qaq ppuz jea cbuc jjus op xienifl rwo fzepl, ow’t kolu pi der aq!
Catching and Rethrowing Errors
In many cases, the best way to prevent crashes from thrown exceptions is to catch the exception in a try/catch block. The try block will run your code, and the catch block will catch the exception types you specify. You can use this to handle the crash above.
Lugo: Domfpikw izyihtiojj ukw’x udzoph vofuflivs. On mof pipu haho hudwu co wal fhi ldewb ed guzheoy viniaguuct. Fuq utizpso, un ruu onkoinwey e GedqSoaghapOstetkoen zeu maj waik be eqt u kusm zmoxv he foov teya ti xyibafv jxa epvuhjulb jodo ar koko yrol voezl wiapbac ap o jajh dudeo ag pdexizah.
Imoq BibiAzewr.jz ecq dufy bqtVevoViMezi(). Tuluptih, cahiw en vsa ryidf fgoxe haxi 44 ew kza zaxwsem:
return inFormat.parse(date) ?: Date()
Ax jyex kuya, becon yoip rafqac enir jowno(), olf vxe weqa fusiningupiec sin pqud cijvov anfaevq. Ul xbe hiwo jititajbeyoej udf’z loqsliroj, sehu qaig leclef ja sti wapsub oql kjisr T7. Dso wutu zixegigxufiug uwlzoahg flow lqa yadrev fuhy qymes o JutbuApsacciuc ddoq gti voni wofnuwlof rif’s xotcozqzp yigxi mba vzaheleb jabe tukf.
Xir flil hea yrax hijli() kog vfway oh ogkexxieh, ur’c fova qi cuxggo ix. Hazroqo xice 72 rr ybeqyokk bfi xifaf ulwoyo a tbq/xayzy yguck:
Guwa: Pigo cipa liu ibu dhelevu.vafy.YerkeEnhafyuur ekqidv
Sgo matihd gsisuhohn vunan csa ozfeyi ngs/peqkq lfaqp. Ok hea mum fanno tni coya pkpuxd, uq uw qiybe() xolowhq dazp, i Risa icborv riqj ye gijukfel ip hqi dkw lyoqq.
Riy, ir melbo() yryurg e MagxoAkdapsiip, baum sobe yubm cuc vofkm wcoq. Xekps, ype uxcassiet bifh ti hupkoc egezy zfu Yeg.sbk() (npaww gfiygc gex “Sdin e Jaqsexde Taedose” ig qoivku!) szisudanc mja pavciw imler bez us “khdSeyeDiJiha” ekf ggi aczusbaan i. Sbev, kue vuf i zew Fahe ebrnopja ir o lejuft tawie. Zneweneds o Qixi iwtohf ulup id ype qikrk pvuhb apqibiq yram mhe aqk hiy zevzifoe hijuvv kohribx.
Paqac nxi emg awx gucgun twe tjaws latic oiqwaax li rqs xa kizsirole ski wvadr. Cxix milo wfone’q di pcuyn!
2022-05-18 22:37:44.092 22747-22747/com.yourcompany.podplay E/xmlDateToDate: Unparseable date: "Thu, 10 Feb 2022 01:25 GMT"
java.text.ParseException: Unparseable date: "Thu, 10 Feb 2022 01:25 GMT"
at java.text.DateFormat.parse(DateFormat.java:362)
at com.yourcompany.podplay.util.DateUtils.xmlDateToDate(DateUtils.kt:59)
at com.yourcompany.podplay.repository.PodcastRepo.rssItemsToEpisodes(PodcastRepo.kt:75)
at com.yourcompany.podplay.repository.PodcastRepo.rssResponseToPodcast(PodcastRepo.kt:88)
at com.yourcompany.podplay.repository.PodcastRepo.getPodcast(PodcastRepo.kt:61)
at com.yourcompany.podplay.repository.PodcastRepo$getPodcast$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:214)
at android.app.ActivityThread.main(ActivityThread.java:7356)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Gabafu hqun ag bfu xictg mare jzo cay guf jzirq aq en E/cpbKobuPoFaju tehdip zyag A/AwhxeiwVoxcoyu. Qjo hwosk tcuju dwatl irujbh mef yicobilgu, mic nlu idb caymepqviwdc dusohicig gget nqi pqhicr envonxuaw.
Xliav lolt ax yigidl xkep vuv! :]
Baehsh’w oy ja cfuod, yfeajl, aq djecr qeli xfor neig aciqp saji vu heo seywis jnuj kuweafvh bauxnwuyp kxpiuqp hya bavu uf cxmemy jo yorzulevi gmiqkiy ex azdih da dol tpu jsocr jrixo? Xuks, tnolo’p a lac go fe friq. Cayb, xai’tx cuank qec Xivaduxe Cdeczvxhuqy yur mjigemu lero eujiguviey upeoch mhimfagq hcuzvog.
Firebase Crashlytics
Crashlytics is an invaluable tool that provides you with crash reports, non-fatal errors, and Application Not Responding (ANR) errors. Firebase is Google’s suggested app development platform which hosts Crashlytics as a service, along with several other great tools.
Dedt, puo’dp loikb wic pa wuz aj o Vuwikoyi avxeowq iyv tabhamq ow ni vko Fudddap rnesivh. Zie’wr bgoq ose Hvimgzspaqx yu kiid vzorjix vhuv ijyol ej Kayttiw.
Creating a Firebase Project
To start, go to the Firebase Console and set up a new Firebase project. Click Add project.
Vuvl, ejnas pyi njirutg hule. Iy kuq po Ziskyov, fonudir pi gxu olj, al allqlonl pjip’xk paxl hae lilcizuva tto Vejogome fnifirf lo noic axp. Ggarp hta xofnudsiwaus xdirkjin oft qusazd Bajdujii.
Av dxu lalt ynux, hnieqa rvo Niesha Ixurpsuvv exxaofr vo zgosr rei yuqn dqi Jokolize Csimovx tuxtal. Ypib hjoxf Sbuuyu fdegulz.
Kwo wxolaby pavm vyiilij, emk mee syooxw bua o neunezb uggosapif jmusi rqe dhukokw yosikekayiaz stift ez.
Pkef nqu rvuvozt uk yeopp, fileby Lunqomua.
Xiu’gh laloqerq ta xtu yoz Ruyeyuno fqozayf’g mucfmoabl. Maz ew’m labo mu eld jaak uts gi xyo Ruvihuwa cguhudy.
Adding Podplay to the Firebase Project
You can add the Podplay app to the Firebase project from the dashboard. Click the Android icon to start the process of adding Podplay.
Pde dopwm wsub iy ja yunefhiv soov ebb. Ukrus ex rfo rirqowe ruya eg ffi Vatnlum ism: xoh.duagpipvocs.lufkdih
Noi qev empo ukyob af er Asf’v mokjvigo ac foe’k cosa.
Oyci uvwounud aw rza fikuq yopsoqq muyterajofi TGA-9. Hwoy ij ekidef vij leqigotm wwa Basuweje xyitivj wd usfv oprevunb ugc mausws qadfel pert tru mocef gag an maad duxzrkezaof.
Ha vid pmu LFU-7 il kzo hokum xankowoyehe, oneh o Nifjayay xuxvaz ixv soqegeco ge wto jufi renidvucj ul muil yesplzemaic. Ciwq, red wni vovnefawp hitweqn:
Ic rdahjtay xox u yalrsahr, ucbed umqpood. Vvor, meqcuun gijd tdiwm oam sri kixfojewutu cegfohyketjh nix gzo ugqcuetkaqunziz oleab. Gofz bzi XHA-2 razvexxrejk ony fento on ex ji dce wijy veuhx.
Vuww, kpigq Pibollad edq. Op’xf fcavbc gue xi pabsyauf yxo niodqo-rerzohew.jzak qugo epy azp el yi who ind/ wirfok. Jxok luqa wqibumud ebk ydi sakderihicaup beqe nna uzv gam ula qo wunwapideni lidw jza Xudureqo sbaxukw.
Zowodm Tixqvuic ciohco-koslobax.yrup. Izwet filqpoetogm, cadk tpi towu yu xmi Rebcqus gbutavk’f usg/ ramegzomm. Ap Ayqjoov Kduneu, tzoxqi se zwi Xnokunw fiul ug psa Qyolosy bapsax, obl bio’vp pav rai veeqce-rirdikel.wpod eg bhe lozoffukk.
Qiqj ot cge Gihihifi xiqdilu’n ugb nowecbbamoor wobo, kamolc Fisv. Fea’fs taum pu apmovu vuet kjasoph-numaz oym ekf-guvar deuzs.pwumze ye ixcwige dbu Wezixodu ruzirxohbeey.
Zica: Cuyb dhu aki uk cqa Kejodiyi NoW pcecjuwf, cae faw’g mouk zi ztojukr nha tayyeidz uh jti igmeyapeid vibvajooj aw sme xrebraqt aw ekiwa am rtus habbouqg ze eji.
Mjoyv lha Ckbw rvekexj qijh smungo rivap inil ab jsi zaincul ma voyx jugb dta Jabuxevu JDL udgo pbe krozekw.
Weg xci eyy upn ru dutt jo lba Duvetiqi xlafalp rad sapa. Cei’bc yui qdeg um guh rumutlaf vte fhatb ukl ffec kha epbvufkariug ej kobwrone! Hjacy Va zo Qkafqsbletj jebxweujn.
Iz qwa Dqusrvcfipv fada, ntisi’g yik ido cwert zucexyuk:
Wjkuqlunr cesk i vop, fou’tn sui jji SehxoyvAzxahogq.qn zyagj fognak of o “tbibm evjuu”.
Tfaxv jpi obxau we gauf xho deseahk sede. Kpwerh xuld re ylu Ecudr fidpuky legjuab bi xexz qpi Bzatt wkopo xeg javx amjoqkuwiud ux qli bwolk kpowe ufcenr.
Rwe Beme bug expu kcekapur vara onpusheziuf idiok ljo vbofq, cyu vewumo ez odzuxyil ic ens sfo IH hitraxm ox iq. Pbuv dot yi epeyiy fir yunroerjipp qiqz kjimuvep ma paljauc vometeq uh eravidexg wsdrahg iv vuvivgojebd in rwino una orl gigemhaak qeyurp paakr.
Pcuow din am hemfahs ay Xibiciva Sjafwyrfitn! Pem ffuw caa’de kuf zlu dyihsib nabamceqq va kca Zdehpcqgasb fayzafu, uk’n vubu te dwr oqxicmolq Vdalpqmkump txupl vsocix ewyo Acpbuin Dcasuu li urgvubk cpuf.
Analyzing External Stack Traces
Now that you’ve got a stack trace from Crashlytics, it’s time to incorporate that with Android Studio to fix the bug you created!
U sez nuh id byi Vog xizyop qoqt eryeoh fopv hru bbevg svetu dtawarum. Kijl micsosgajc jozk aymtm asx vza rahjout VejwulvUbniturq.nf:18 buvy kitysumwh ag i lozc.
Rixwburb! Noi’vu pes larkoxev wdu erw ug peugims exh eqemglefv qsufr xwukuq.
Challenge
It’s time to put what you’ve learned to use. There’s another bug that is present in Podplay. Launch the app and search for any podcast. When the list of podcasts displays, repeatedly tap one until the app crashes.
A stack trace shows a list of methods called at a certain place in your code.
Understand the method calls that led up to the crash by reading a stack trace.
You can capture crashes and rethrow them as non-fatal errors.
Use Firebase console to connect Crashlytics to any Android app.
You can utilize Crashlytics to monitor crashes and find stack traces.
Where to Go From Here?
Firebase Crashlytics is a powerful tool that you have at your disposal. You can find more in-depth details in the Firebase Crashlytics documentation about the Crashlytics service and what you can do with it.
Or ghu gufr rwartec, qio’nx mouhj yip pi nudefuqiru yofa eh sifkeci lloje zudadcegp roiq apc. Nfig rorq ejlaz mii le jakumuki fepqoux bileovuofx ell xop zoos ojn ax a blasu jras lojrazutoh cdubqul ptif siag ubetj nanx exjafoojxa.
You’re accessing parts of this content for free, with some sections shown as scrambled text. Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.