检查Eclipse中的java类实例变量值

时间:2023-01-17 19:30:37

In an application, I have a class with a few member variables and methods. Calling the method with bad parameters produces a AssertionError. I've setup the debugger to halt on uncaught exceptions.

在应用程序中,我有一个包含几个成员变量和方法的类。使用错误参数调用方法会产生一个AssertionError。我设置了调试器来停止未捕获的异常。

Problem is, when switching over to the debug perspective, I can only see the class instance (on which the function was called) and the two parameters. I cannot expand the class instance to see the values of its member variables. There is a space to the left of the instance so I would assume that there should be an arrow there so one is able to expand it in a similar way as in the Outline.

问题是,当切换到debug透视图时,我只能看到类实例(函数被调用)和两个参数。我无法展开类实例以查看其成员变量的值。在这个实例的左边有一个空间所以我假设这里应该有一个箭头所以一个可以以类似于大纲的方式展开它。

Is there a configuration or something I must enable for this? Or have I misunderstood the variables window?

是否有配置或必须为此启用的东西?还是我误解了变量窗口?

If it matters, this is Eclipse 3.2.2 in Ubuntu Linux.

如果重要的话,这是Ubuntu Linux中的Eclipse 3.2.2。


[Update] I downloaded a new release from http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/R/eclipse-java-galileo-linux-gtk.tar.gz

[更新]我从http://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/galileo/R/eclipse-java-galileo-linux-gtk.tar.gz下载了一个新版本

"About Eclipse" now reports "Build id: 20090619-0625".

“关于Eclipse”现在报告“构建id: 20090619-0625”。

Testcase:

Testcase:

class Foo {
    private int bar;

    Foo() {
        bar = 1;
    }

    public void set(int newbar) {
        assert (newbar<0);
        bar = newbar;
    }
}

class Test {

     public static void main (String[] args){
         Foo f = new Foo();
         f.set(5);
     }
}

Obviously, this code produces the assertion exception. But the only change is the icon for "this" which changed from a green circle to a blue triangle in the new version. Still cant find a way to expand it. Here, I can see "this" for the Foo instance, as well as "newbar" and its value, to clarify, what I want to do is expand "this" and see its current value for "bar".

显然,这段代码会产生断言异常。但是唯一的改变是“this”的图标在新版本中从绿色的圆圈变成了蓝色的三角形。还是找不到扩展它的方法。在这里,我可以看到Foo实例的“this”,以及“newbar”和它的值,来澄清,我想要做的是展开“this”,并看到它的“bar”的当前值。

2 个解决方案

#1


2  

No, you haven't. Normally the first line in the debug view should be an entry "this", which represents the instance you are currently running in. It should have a "+", which you click to expand the list of instance variables.

不,你没有。通常,debug视图中的第一行应该是一个条目“this”,它表示当前正在运行的实例。它应该有一个“+”,单击它可以展开实例变量列表。

If this doesn't work, maybe you are in the wrong stack frame (you can select it in the stack trace listing), or Eclipse cannot resolve your source code location, or something else is wrong.

如果这不起作用,那么您可能处于错误的堆栈框架中(您可以在堆栈跟踪列表中选择它),或者Eclipse无法解析源代码位置,或者其他问题。

Try creating a small testcase where this is reproducible, and posting that. Then we'll see...

尝试创建一个可以复制的小测试用例,并发布它。然后我们将会看到…

BTW: Eclise 3.2.2 is rather old. Consider upgrading to 3.5 to see if the problem persists. You can install several Eclipse versions side by side (just unzip to a directory), so no need to clobber your existing installation.

顺便说一句:Eclise 3.2.2很老。考虑升级到3.5,看看问题是否还存在。您可以同时安装几个Eclipse版本(只需解压缩到一个目录),因此不需要对现有的安装进行破坏。

#2


2  

After some discussion in #eclipse, we found that the VM was the problem. I was running:

在#eclipse中进行了一些讨论之后,我们发现VM是问题所在。是我跑:

/usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0/bin/java

Changing it to:

改变:

/usr/lib/jvm/java-6-openjdk/bin/java

and suppling a -ea flag as argument to the VM let me expand the class instance inspecting the value of bar. Problem solved.

将-ea标志作为参数提供给VM让我展开类实例来检查bar的值。问题解决了。

#1


2  

No, you haven't. Normally the first line in the debug view should be an entry "this", which represents the instance you are currently running in. It should have a "+", which you click to expand the list of instance variables.

不,你没有。通常,debug视图中的第一行应该是一个条目“this”,它表示当前正在运行的实例。它应该有一个“+”,单击它可以展开实例变量列表。

If this doesn't work, maybe you are in the wrong stack frame (you can select it in the stack trace listing), or Eclipse cannot resolve your source code location, or something else is wrong.

如果这不起作用,那么您可能处于错误的堆栈框架中(您可以在堆栈跟踪列表中选择它),或者Eclipse无法解析源代码位置,或者其他问题。

Try creating a small testcase where this is reproducible, and posting that. Then we'll see...

尝试创建一个可以复制的小测试用例,并发布它。然后我们将会看到…

BTW: Eclise 3.2.2 is rather old. Consider upgrading to 3.5 to see if the problem persists. You can install several Eclipse versions side by side (just unzip to a directory), so no need to clobber your existing installation.

顺便说一句:Eclise 3.2.2很老。考虑升级到3.5,看看问题是否还存在。您可以同时安装几个Eclipse版本(只需解压缩到一个目录),因此不需要对现有的安装进行破坏。

#2


2  

After some discussion in #eclipse, we found that the VM was the problem. I was running:

在#eclipse中进行了一些讨论之后,我们发现VM是问题所在。是我跑:

/usr/lib/jvm/java-1.5.0-gcj-4.3-1.5.0.0/bin/java

Changing it to:

改变:

/usr/lib/jvm/java-6-openjdk/bin/java

and suppling a -ea flag as argument to the VM let me expand the class instance inspecting the value of bar. Problem solved.

将-ea标志作为参数提供给VM让我展开类实例来检查bar的值。问题解决了。