Bugfix for a Crashing Activity, 51/100 Days of Code
I ran into an all too familiar bug when adding Activities to an Android Project.
For some reason, the app would crash whenever I tried to start a new Activity. You can find the video on this at the bottom of the page and a link to the source code here.
Whenever I clicked the option in the app for displaying the list of scavenger hunt riddles, it crashed! I checked the onClickListener attached to the TextView option, and the ids used in the layouts. Everything appeared fine. So what was causing the app to crash instead of changing Activities?.
To fix this, I used the debugger to isolate the cause of this bug. The debugger documents errors in a console window and provides useful information for fixing bugs.
After attaching the debugger to my virtual device, I clicked resume in debugger area and used the app as I described earlier. When I clicked the option, the app crashed same as before.
I reviewed the messages in the console window. An error appeared saying it is unable to find the class passed in the intent. The terminal then asks if I updated AndroidManifest.xml with the Activity tags for the new Activity (click below).
Oops. I felt a little embarrassed by this bug. The issue was easy to catch, but the debugger helped me locate the specific issue. I didn’t find errors in my code and the app compiled without issue. The debugger was able to point me in the right direction by logging the distinct cause of the application crash.
For more on this, watch the YouTube video below. For the source code click here
Join the mailing list to see updates like this every week!
Coding Fanatic
Image by Steve Buissinne from Pixabay