开发者

Android: More descriptive error please!

开发者 https://www.devze.com 2023-02-06 01:55 出处:网络
I\'m using Eclipse. I\'m burning hours trying to debug my first (very simple) android app. When I hit an error, I don\'t get a proper exception with a description of what went wrong, I get a screen

I'm using Eclipse.

I'm burning hours trying to debug my first (very simple) android app.

When I hit an error, I don't get a proper exception with a description of what went wrong, I get a screen asking for source code and a "Suspended(Exception RuntimeException))" on the debug log.

I'开发者_开发问答m resorting to logging each line to see where the last execution point was, and then trying to understand by googling why the following line would cause an error.

See my screenshots: Error and Missing Source.

The highlighted line:

SimpleCursorAdapter scaSights = new SimpleCursorAdapter(this,R.layout.sight_row,sightsCursor,fromDisplayFields,toDataFields);

is where the exception occurs. I've got no idea what's wrong there, but a good exception message would help, not a prompt for source code.

Any help is hugely appreciated!


It's happening because you have an exception on a line you are tracing over, and you are now tracing into the SDK classes where the exception is being thrown from. This is normal and expected, although not terribly useful. When this happens, there's not much you can do beyond just "play" the debugger and look at the logcat log to see the exception stack trace.

If you want to see the exception in the debugger, you can put a try { ... } catch (Throwable t) around the block, then set a breakpoint in the catch and inspect the exception, and the state of your other objects.


logcat normally prints any uncaught exceptions. An alternative to reviewing the logs is to surround that code with try-catch, and then print the error message and/or stack trace.


Hmm. From what I can see in your wtf.jpg pic, that line 86 does not appear to be part of the stack trace, so I don't know if it is causing the problem.

Some notes to help with debugging:

  • You can introduce break points (say at line 71) and step through the code (press the Step Over icon)
  • If you want to step through a function you wrote and called, press the Step Into icon
  • If you try to step through one of the android functions (that you did not write) you will see the Source not Found error. This does not mean the error occurred here
  • You can try setting 2 break points (say at line 71 and 90) and when you hit the first one, press the Resume Icon - which will keep running until it hits the 2nd break point. If it doesn't crash, then you can be sure the error did not occur here.
  • You can filter logcat to error message only by pressing the red (E) button. Press the (V) button to return.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号