- Prerequisites
- Using LogCat
- Seeing a Common Mistake
- Testing Views
- Tracing Code
Seeing a Common Mistake
Once you've fixed the first bug, go back and run the application again. Oh, no! Another bug in approximately the same place? This time the error is a little less obvious:
03-01 18:07:53.996: ERROR/AndroidRuntime(24205): java.lang.IllegalStateException: Could not execute method of the activity
What does that mean? The next several lines of output after a typical error will be the call stack and trace. This time, when looking all the way down we can see that it's being caused by a line of code within the doShowOtherScreen() method. (At least our method is being called.)
03-01 18:07:53.996: ERROR/AndroidRuntime(24205): at com.mamlambo.articles.bugged.BuggyActivity.doShowOtherScreen(BuggyActivity.java:19)
If you look at the specific line of source code that this output is referencing (which may be slightly different than Line 19 in your environment), you'll see that the problem is occurring with the startActivity() method call. From experience, we know that one of the more common mistakes made by new Android developers is forgetting to register activities within the AndroidManifest.xml file. Go look at the manifest file. See anything wrong?
Yup, that's right. We have two activity classes listed there, but one is named SecondActivity, which doesn't even exist. We must have mistyped the name; we meant to type OtherActivity. Fix the Android manifest file and you've fixed another bug in this application.