如何使用Eclipse正确调试Java(Android)?
我在调试代码时遇到问题。我的一个 AsyncTasks 抛出 RuntimeException,但我不知道代码中的哪一行对此负责。由于我对 Eclipse 和 Java 总体来说是新手,所以所有这些都让我感到相当困惑。
Eclipse 的调试窗口显示我的 AsyncTask 由于 RuntimeException 已被挂起。下面,有三行指出了某些代码行。然而,这些行不存在于我的代码中,这就是为什么我不知道是什么导致我的应用程序崩溃。我是否遗漏了 Java/Android 调试的一些重要内容?
顺便说一句,这是给我的三行:
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1086
ThreadPoolExecutor$Worker.run() line: 561
Thread.run() line: 1096
我应该如何处理它?帮助将不胜感激。
I am having problems with debugging my code. One of my AsyncTasks throws a RuntimeException, but I don't know which line in my code is responsible for this. Since I am new to Eclipse and Java in general, all of this is rather confusing to me.
Eclipse's debugging window shows me that my AsyncTask has been suspended because of a RuntimeException. Below that, there are three lines which point out certain lines of code. However, those lines do not exist in my code which is why I do not know what causes my application to crash. Am I missing something essential about debugging in Java / Android?
These are the three lines which I am given, by the way:
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1086
ThreadPoolExecutor$Worker.run() line: 561
Thread.run() line: 1096
How am I supposed to work with that? Help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 ddms 中,如果您无法在 ddms 中找到 logcat,则可以在 logcat 窗口中获取与错误、警告或其他类型消息相关的消息,然后转到菜单 Window->Show View-> logcat 单击它,您现在将能够在同一个 ddms 中看到该消息,您还可以从中获取设备窗口,选择设备,以便您可以调试或从该设备获取消息到 logcat 中。
现在检查一下,您可以在此 logcat 详细信息中找到错误详细信息
in the ddms you can get the message related to the error, warning or other type of messages into the logcat window if you can't able to find the logcat in the ddms then go to the menu Window->Show View->logcat click on that and you'll be able to see the message now in the same ddms you also get the device window from that select the device for you can able to debug or get the message from that device into the logcat.
now check this way you can find your error detail into this logcat details
您最好使用 logcat - 这将显示堆栈跟踪和引发错误。我从来没有成功地单步执行 DDMS 中的代码,但是根据 logcat 中显示的错误,通常很容易找出引发错误的原因。
如果在 Eclipse 中不可见,请参阅 Pratik 的有关打开 logcat 的答案。
You're best using the logcat - this will show the stacktrace and the error raised. I've never had great success stepping through the code in
DDMS
but with the errrors shown in the logcat it's normally pretty easy to work out why the error was raised.See Pratik's answer for opening the logcat if it isn't visible within Eclipse.
Rajeev 说得对 - 当您在异常上设置断点时,调试器将在引发异常的行上中断,而不是在捕获异常的行上中断。通过这种方式,您可以看到导致异常的原因。
Rajeev got it right - when you set a breakpoint on an exception, the debugger will break on the line that throws it, not the line that catches it. In this way, you can see what is causing the exception.