在 Eclipse (Java) 中调试;中断查看值时无法将鼠标悬停在变量上
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2029533/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging in Eclipse (Java); can't hover over a variable when breaking to view the value
提问by Ted
I'm using Eclipse to code Java (for Android) and I'm trying to debug the code as I normally do (i normally do C# though).
我正在使用 Eclipse 来编写 Java(用于 Android),并且我正在尝试像往常一样调试代码(尽管我通常使用 C#)。
From what I can tell, debugging in Eclipse is really bad. I don't know if I'm doing something wrong, but it seems to be just awful.
据我所知,在 Eclipse 中调试真的很糟糕。我不知道我是不是做错了什么,但这似乎很糟糕。
This is the code that is being run, I get some sort of exception and I want to see what the Exception is, by breaking in the "catch"-clause and viewing the variable "e":
这是正在运行的代码,我得到了某种异常,我想通过打破“catch”子句并查看变量“e”来查看异常是什么:
try
{
ConnectivityManager connectivityManager = (ConnectivityManager) this.getSystemService( Context.CONNECTIVITY_SERVICE );
NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo();
NetworkInfo mobNetInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
NetworkInfo.State state = mobNetInfo.getState();
}
catch(Exception e)
{
Log.v("MyAp", e.toString()); // I break on this line, and want to see what e is
}
The problem is that I cannot see "e" by holding my mouse over it (as I can in my beloved Visual Studio).
问题是我无法通过将鼠标悬停在“e”上来看到它(就像在我心爱的 Visual Studio 中一样)。
Now, I know that I can bring up the tab "Variables" which lists all variables accessible from when I'm breaking, but that's not optimal.
现在,我知道我可以调出“变量”选项卡,其中列出了我中断时可访问的所有变量,但这不是最佳选择。
Just so I know - Eclipse has no way of "hovering" over the variable you are interested in, as in Visual Studio?
就我所知 - Eclipse 无法像在 Visual Studio 中那样“悬停”在您感兴趣的变量上?
Edit
编辑
Thanks for the answers. However, still have the same problem =(
感谢您的回答。但是,还是有同样的问题=(
采纳答案by Powerlord
As far as I can tell, you have to be in Debug view in order to hover over objects and see their properties. At least that's how my copy of Eclipse 3.4 works.
据我所知,您必须处于调试视图中才能将鼠标悬停在对象上并查看其属性。至少我的 Eclipse 3.4 副本是这样工作的。
Of course, you also need to be in Debug view to have the Step Into, Step Over, Continues, etc... buttons...
当然,您还需要在 Debug 视图中才能拥有 Step Into、Step Over、Continues 等...按钮...
回答by Roger Thomas
Go to Preferences-> Java-> Editor-> Hovers and tick the box 'Variable Values'. If you want Hover to happen automatically then leave the Key Modifier section blank.
转到首选项-> Java-> 编辑器-> 悬停并勾选“变量值”框。如果您希望 Hover 自动发生,请将 Key Modifier 部分留空。
回答by Stijn de Witt
There seem to be bugs in Eclipse related to this:
Eclipse 中似乎存在与此相关的错误:
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=317045
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=330061
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=286237
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=317045
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=330061
- https://bugs.eclipse.org/bugs/show_bug.cgi?id=286237
So, yes it is supposedto work, but it doesn't always. I'm having this issues on some classes. It seems to be consistent which classes work and which don't, probably related to what jar the class is coming from etc, but I have no real clue as to what causes it. Would love to see some reproduction scenario.
所以,是的,它应该可以工作,但并不总是如此。我在某些课程上遇到了这个问题。哪些类有效,哪些无效,这似乎是一致的,可能与类来自哪个 jar 等有关,但我不知道是什么原因造成的。很想看到一些再现场景。
回答by Bryan Shannon
I have also found that in the "Debug" view (the tab with the little green bug as an icon) where it shows all the threads, Eclipse sometimes doesn't show the variable's values if the currently breakpointed thread isn't selected.
我还发现,在显示所有线程的“调试”视图(带有绿色小虫子图标的选项卡)中,如果当前断点线程未被选中,Eclipse 有时不会显示变量的值。
If anyone else runs across this problem, then you might have hit a breakpoint, but the currently running thread isn't the one highlighted in the "Debug" window.
如果其他人遇到此问题,那么您可能遇到了断点,但当前运行的线程不是“调试”窗口中突出显示的线程。
回答by Jeremy Raymond
You can also highlight the variable, right click, and choose to watch it. Then it shows up on the watch tab. You can also set automatic break points that trigger on the exception being thrown rather than at a particular line of code. There is not'hover' option to view the variable as in Visual Studio in recent versions of Eclipse.
您还可以突出显示变量,右键单击,然后选择观看它。然后它显示在手表选项卡上。您还可以设置在引发异常时触发的自动断点,而不是在特定代码行处触发。有没有“悬停”选项来查看变量在Visual Studio在最新版本的Eclipse。
回答by kfb
This might seem a bit strange, but do you know that the code window has focus? I have observed that sometimes the appearance of the tooltip depends on whether a view has focus or not (which I guess is an SWT bug).
这可能看起来有点奇怪,但你知道代码窗口有焦点吗?我观察到有时工具提示的外观取决于视图是否具有焦点(我猜这是一个 SWT 错误)。
回答by jsalatas
Go to Preferences
-> Java
-> Editor
-> Hovers
, and click Restore Defaults
.
转到Preferences
-> Java
-> Editor
-> Hovers
,然后单击Restore Defaults
。
回答by Nisarg Panchal
Found it, Goto: Preferences > Java > Editor > Hovers - Javadoc (click on it and remove the ctrl+shift keys from there), then it should work normally.
找到它,转到:首选项 > Java > 编辑器 > 悬停 - Javadoc(单击它并从那里删除 ctrl+shift 键),然后它应该可以正常工作。
回答by Silverio Martínez García
I think that the correct answer is the @RogerThomas one.
我认为正确的答案是@RogerThomas。
Go to 'Window' -> 'Preferences' -> 'Java' -> 'Editor' -> 'Hovers' Then check 'Variable Values'.
转到“窗口”->“首选项”->“Java”->“编辑器”->“悬停”然后检查“变量值”。
If the 'Variable Values' option collides with 'Combined Hover', uncheck last one or configure new keys for it.
如果“变量值”选项与“组合悬停”相冲突,请取消选中最后一个或为其配置新键。