简体   繁体   English

如何使用Eclipse正确调试Java(Android)?

[英]How to properly debug Java (Android) using Eclipse?

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. 我的一个AsyncTasks抛出一个RuntimeException,但我不知道我的代码中哪一行对此负责。 Since I am new to Eclipse and Java in general, all of this is rather confusing to me. 由于我一般都是Eclipse和Java的新手,所以这一切对我来说都相当混乱。

Eclipse's debugging window shows me that my AsyncTask has been suspended because of a RuntimeException. Eclipse的调试窗口显示我的AsyncTask因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? 我是否遗漏了有关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. 非常感谢帮助。

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. 在ddms中你可以得到与错误,警告或其他类型的消息相关的消息进入logcat窗口如果你无法在ddms中找到logcat然后转到菜单Window-> Show View-> logcat click在那,你将能够在相同的ddms中看到消息,你也可以从设备窗口中选择设备,因为你可以调试或从该设备获取消息到logcat。

now check this way you can find your error detail into this logcat details 现在检查这种方式,您可以在此logcat详细信息中找到您的错误详细信息

You're best using the logcat - this will show the stacktrace and the error raised. 你最好使用logcat - 这将显示堆栈跟踪和引发的错误。 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. 我从未在DDMS逐步完成代码,但是由于logcat中显示的错误,通常很容易找出错误引发的原因。

See Pratik's answer for opening the logcat if it isn't visible within Eclipse. 如果在Eclipse中不可见,请参阅Pratik打开logcat的答案。

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. Rajeev做对了 - 当你在异常上设置一个断点时,调试器会在引发它的行上断开,而不是捕获它的行。 In this way, you can see what is causing the exception. 通过这种方式,您可以看到导致异常的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM