I’m in a coding course for Android development. I’m, at best, a beginner-level coder; and, when it comes to Java/Kotlin, forget about it: I’m as entry-level as they come.
I’m finish up this tic-tac-toe game and everything is chugging along until I get to the very end; implementing a “play again” functions, i.e., a game reset. I press the “PLAY AGAIN” button and the app crashes! What?! I have no idea way. Here’s what I do:
- I comment out the actual code, leaving only the function declaration itself. I run it. No crash.
- I then un-comment only the declaration of variables, leaving all for loops and if statements commented. I run it. No crash.
- I then un-comment one for loop at a time, but I leave it’s innards commented out. I run it. Still… no crash.
- I then un-comment one for loop’s “guts” and run it. No crash. Rinse and repeat, and boom! Crash.
But what was it about that line of code? Here’s that mysterious line of code, by the way:
GridLayout gridlayout = findViewById(R.id.gridlayout);
I couldn’t figure it out… until, some time later… I’m embarrassed to say, I remembered to check… drum roll please… the error log. Here’s the fix:
android.support.v7.widget.GridLayout gridLayout = findViewById(R.id.gridLayout);
I’m such a rookie. That should have been step one. Instead, being the rookie that I am, I opted for a step-by-step commenting and un-commenting of lines of code until I literally tripped over the problem. Not only is that inefficient, it betrays just how little I know. I’m so new that I can’t even narrow the problem down to a few lines!
There is a silver lining, though. I learned a better way to approach a problem / error. I learned more about types and their relationship to the activity’s XML document. I learned quite a bit, actually. I’m not surprised.
I immediately thought back my days as an electronic technician in the Navy, and to what my division Chief once said to a team of us that had been beating our heads against the wall, trying to solve a communications issue between our ship and the rest of the expeditionary strike group. He walked in, took a look at our tired, miserable, and pitiable faces, and smiled. He then said, “Faults are bad for liberty, but great for learning,” as he walk out, still smiling.
Amen! Ain’t that the truth! I love faults, errors, problems, and obstacles for one overarching reason: You come out a smarter, better, and stronger person on the other side, guaranteed! Take care and keep coding.
</post>