Java 当我从 JDK 调试类文件时,为什么 Eclipse 不显示局部变量值?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23057814/
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
Why Eclipse doesn't show local variables values when I debug class file from JDK?
提问by gstackoverflow
I want to debug .class
files. For example some from the JDK. I downloaded the sources and attached them.
我想调试.class
文件。例如一些来自 JDK。我下载了源代码并附上了它们。
public File[] listFiles(FilenameFilter paramFilenameFilter)
{
String[] arrayOfString = list(); // now we here
if (arrayOfString == null) return null;
....
}
Then I type F6and move to the next line. After that, I try to watch the value of arrayOfString
but I see the following:
然后我输入F6并移动到下一行。之后,我尝试查看的值,arrayOfString
但我看到以下内容:
Expression view:
表达式视图:
Is it normal a situation? Is there a way to debug?
这是正常的情况吗?有没有办法调试?
Update 1:
更新 1:
Update 2:
更新 2:
Update 3:
更新 3:
采纳答案by Absurd-Mind
The problem is that the source/class files from the JDK are compiled without debug information and therefore eclipse can't inspect these vars. See this answerfor more information.
问题是来自 JDK 的源/类文件是在没有调试信息的情况下编译的,因此 eclipse 无法检查这些变量。有关更多信息,请参阅此答案。
To solve your problem you need to get a different rt.jar or compile it yourself
要解决您的问题,您需要获取不同的 rt.jar 或自己编译
回答by emphywork
You can see all the variables values in the Variables window. Expressions will only show values when they have scopes, but sometimes they do not behave the way we want to.
您可以在“变量”窗口中查看所有变量值。表达式只有在有作用域时才会显示值,但有时它们的行为并不像我们想要的那样。
So my suggestion is you should use "Variables"window to view all the variables and its value.
所以我的建议是你应该使用“变量”窗口来查看所有变量及其值。
回答by Bhushan Kawadkar
yes you can, use inspect
option from the menu (just below watch) by selecting the expression with mouse cursor. Be sure that you have selected the whole expression correctly.
是的,您可以,inspect
通过使用鼠标光标选择表达式来使用菜单中的选项(就在手表下方)。确保您正确选择了整个表达式。
like if below is the code
就像下面是代码
if(object.value())
{
// some code
}
so select only object.value()
and right click and select inpsect
所以只选择object.value()
并右键单击并选择inpsect
And another option is to see variable values in variable
tab available
另一种选择是在variable
可用选项卡中查看变量值
回答by xwhyz
I recommend using ctrl
+shift
+i
on selected expression which is inspect
.
我建议使用ctrl
+ shift
+i
上选定的表达是inspect
。
Additional option is to add Display
view to your environment where you can type your own expressions and inspect those as if they're placed in code.
其他选项是将Display
视图添加到您的环境中,您可以在其中键入自己的表达式并检查它们,就像它们被放置在代码中一样。
回答by Alexis Dufrenoy
In the Expressions view you can enter any expression and Eclipse will try to evaluate it in the current execution context. Which means if your expression is not valid in the current context (for example, you try to evaluate object.myMethod() and object is null), you will get the error you have shown.
在 Expressions 视图中,您可以输入任何表达式,Eclipse 将尝试在当前执行上下文中对其求值。这意味着如果您的表达式在当前上下文中无效(例如,您尝试评估 object.myMethod() 并且 object 为 null),您将收到您显示的错误。
回答by Minnu
Take Windows -> Prefrences -> Java -> Complier, fom the Eclipse menubar and verify checkbox for 'Add Variable attributes to generated class files (used by the debugger) is checked.
以 Windows -> Prefrences -> Java -> Complier,从 Eclipse 菜单栏,并验证“将变量属性添加到生成的类文件(由调试器使用)”复选框被选中。
回答by Jay Snayder
When this started to happen to me, it wasn't resolved by some of these solutions and it wasn't the only problem that I began to start experience.
当这开始发生在我身上时,其中一些解决方案并没有解决它,这并不是我开始体验的唯一问题。
I would like to propose another solution (for myself included). Migrate over to Android Studio as much of your workspace as you can and start familiarizing yourself with the new IDE. If developing for a company, try and get it worked into your hours to have time set aside to migrate these because some are going to be easy and some with NDK components will likely not be.
我想提出另一个解决方案(包括我自己)。将尽可能多的工作区迁移到 Android Studio,并开始熟悉新的 IDE。如果为一家公司进行开发,请尝试将其投入工作,以便留出时间来迁移这些,因为有些会很容易,而有些带有 NDK 组件的则可能不会。
But, with Eclipse being dropped from support and the focus on Android Studio from Google it is best for us (only in my opinion of course) to start learning the new environment. It is now at a pretty stable point that it surpasses the usual Android application development side of programming over Eclipse.
但是,由于 Eclipse 不再受支持并且 Google 将重点放在 Android Studio 上,因此我们最好(当然仅在我看来)开始学习新环境。它现在处于一个非常稳定的点,它超越了通过 Eclipse 编程的通常的 Android 应用程序开发方面。