Try the following:
public void onCreate (Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.main);
Log.d ("HelloWorldActivity.onCreate ()", "setContentView () completed");
}
Place a breakpoint in the log statement.
Run the application in the emulator and note that it works step by step to see the LogCat entry in Eclipse.
Change HelloWorldActivity to extend from ListActivity instead of Activity.
public class HelloWorldActivity extends ListActivity {
- Run the application in the emulator and note that it cannot execute the log statement.
My question is NOT why this fails. My question is: how would you decide to debug this failure? All I see in the Eclipse Debug panel is a RuntimeException. I see that LogCat has a bunch of messages, but it is huge, and I searched for it, but I can not find anything to indicate what was wrong or where an exception occurred in my code. I cannot find a way to display a message inside a RuntimeException or a stack trace to find out which line of code raised the exception.
I assume that there should be more efficient ways to use the tools to find errors, but I am new and can not find a better way to debug, except to wrap everything that I encoded in try / catch. I would expect to find a message in LogCat generated by throwing an exception. I would expect the Debug window to allow you to check the contents of exceptions. I am not saying that such methods do not exist, I am saying that it is difficult for me to understand how a beginner is, how to debug and ask what methods exist and how to use them?
So just put:
- How would you find this error if you did not know what causes it?
- What methods would you use to find out the cause?
- How would you know the details of the exception?
- Generally, how do you detect problems in your Android code using Eclipse?
Numerous suggestions and discussions are welcome. :)
I would include the contents of LogCat, but it is so large that it is not sensible. You should be able to easily reproduce this yourself, so I left it. Maybe there is something in LogCat to help me, but since it is so large and even a small program works, I need a hint on what to look for and how to interpret it, throwing an exception caused by an API call. I see other messages that indicate that something should be in LogCat, which, although it may be true, I find nothing. If you think something should be in LogCat, please run the test yourself and copy the lines into your answer, which I should find.
Thanks.
========
The list of summary methods so far is as follows:
Invasive methods: 1. Place a toast in the code places where you want to see what you have completed. 2. Place a try / catch around the code where you think it is possible to throw an Exception. 3. Comment on the code and recompile and retest.
Non-invasive methods: 1. Use a debugger. Breakpoints, variable checking ... 2. Monkey stress tester. 3. Download the Android source library. 4. Use LogCat filters to see if "Caused By" is displayed.
It is unclear whether: 1. Debugging a version of the Android library that has additional logging, approvals, or other additional help is available. 2. Ability to check exceptions in Eclipse through the Debug panel or other methods. 3. A way to define a more global try / catch exception handler. 4. Ability to debug through the source code of the Android library.
Not available: 1. Non-invasive way to view the contents of the Exception or where the exception occurred.