简体   繁体   English

Eclipse无法在包中调试新创建的类

[英]Eclipse cannot debug a newly created class in a package

In Eclipse, I have a Java package in a project that I can debug. 在Eclipse中,我在一个项目中有一个Java包,可以调试。 I added a new class called Clothing by right-clicking on the package and hitting New->Class. 我通过右键单击包并单击New-> Class,添加了一个名为Clothing的新类。

Now, this code works. 现在,此代码有效。 It builds and runs successfully and I can successfully use the Open Declaration function on the window that pops up when I hover over Clothing-related constructors and methods. 它可以成功构建和运行,当我将鼠标悬停在与服装相关的构造函数和方法上时,我可以成功使用弹出窗口上的Open Declaration函数。

However, when I try to debug it by stepping into Clothing, I get a "Source Not Found" and a prompt to edit the Source Lookup Path. 但是,当我尝试通过进入服装进行调试时,出现“找不到源”和提示,提示您编辑源查找路径。 The code still works when I step over it. 当我跳过它时,该代码仍然有效。

I'm sure there's a simple setting that I need to turn on or off but how do I debug this class? 我确定需要打开或关闭一个简单的设置,但是如何调试此类?

Edit: I have cleaned this project, the code is all in one project in my workspace and I have restarted Eclipse multiple times. 编辑:我已经清理了这个项目,代码全部在我的工作空间中的一个项目中,并且我已经多次重启了Eclipse。

This is not because of package/location of your project class, but because you are stepping into constructor while instantiating class for the first time. 不是因为项目类的包/位置,而是因为您是在首次实例化类时踏入构造函数
Even if your class was declared in the same file - you'd likely have same problem. 即使您的课程是在同一文件中声明的您也可能会遇到同样的问题。

When you instantiate your class for the first time, the class itself is loaded by java.lang.ClassLoader first, so your debugger is likely trying to step in ClassLoader's code, which you don't have. 首次实例化类时,该类本身首先由java.lang.ClassLoader加载,因此您的调试器可能会尝试插入您没有的ClassLoader代码。

Solution: 解:
You can tell your debugger to skip ClassLoader part with Eclipse debug filter preferences and it should work. 您可以告诉调试器跳过带有Eclipse调试过滤器首选项的 ClassLoader部分,它应该可以工作。

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

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