1

I wanna debug very simple code that consists of two simplest classes.

package test.pack;

public class TestClass {

    public static void main(String[] args) {
        TestClassTwo tc2 = new TestClassTwo();
    }

}

==================================================

package test.pack;

public class TestClassTwo {

    public TestClassTwo() {
        System.out.println(this);
    }

}

==================================================

So, when I toggle on breakpoint on inizialization of class TestClassTwo and run debug by [F11] and [F5], I should get into constructor of TestClassTwo. But instead of this breakpoint hits in such place where I don't set any breakpoints. It is shown on this pic

I try this on [Eclipse IDE for Java EE Developers] and [Eclipse IDE for Java Developers], also I download and install last version of JDK from oficial Oracle site.

But there is one limitation is that I should to use Java version 1.7 in my project according to the technical task from business side.

I was trying to use solutions from this topic Debug hit without breakpoint - Eclipse, but it was not helpful.

Next, I attach screenshots that can somehow help solve my problem.

Java library in settings of project

Installed JRE in preferences of Eclipse

Java version in cmd

System variables in Environment variables

System variables in Environment variables also

Windows version

2 Answers2

0

You tried to output this, which means reference on this object, but but tried to call it from constructor, which creates this object. Try calling this code after constructor in another method.

Debug probably crashed because of null reference exception, that causes error in call stack, that's why program crashes instantly.

Dima Rich
  • 61
  • 6
0

First of all, you did everything correct up to this point.

The 'error', if you want to call it such, arises when you hit F5. Now this command is called step into, which means that it will continue execution in the next deeper stack layer.

From the code you assumed that this will be the constructor of TestClassTwo, but before java can invoke the constructor it first has to initialize the class itself and that is exactly what the Debug View in the picture indicates.

Side question: Did you press F5 multiple times to get that deep into ClassLoader.loadClass()?


For the current execution you can select the second last line in the Debug View, which is

Launcher$AppClassLoader(ClassLoader).loadClass(String) line: not available

and then hit F7. This will step out of the respective method an continue execution on the previous stack layer, where the call to the constructor of TestClassTwo should follow.


For future debugging you might want to get familiar with Step Filtering. Step filters allow you to exclude certain portions of code from debugging. They will be executed, but eclipse will automatically 'step over' them.

At the corresponding preference page, Java > Debug > Step Filtering, eclipse conveniently provides an option to separately enable and disable step filtering for java.lang.ClassLoader.

Izruo
  • 2,246
  • 1
  • 11
  • 23