Obtener 'Fuente no encontrada' para la clase en la depuración de Eclipse

My top level debug class as specified in the debug configuration is MyDebugClass. Further down in the main, it attempts to launch an instance of class ProblemClass que sea en el mismo paquete as MyDebugClass but it errors out on the constructor invocation line saying "Source not found". The project compiles fine and the .class file is indeed in the target directory, the same place as the .class for MyDebugClass.

I thought there may have been something odd with the classpath so that the same package where the debug main is not included so I made a test class in the same directory and tried to invoke an instance of it and that worked. So that is not the problem.

I also added the following code in MyDebugClass.main to try to debug the issue:

ClassLoader loader = ProblemClass.class.getClassLoader();
Class probCls = loader.loadClass("mypackage.ProblemClass");
//here below is where it errors out

What could possibly be causing this kind of class loading problem? There is a whole bunch of jars in the classpath so could it be that one of them contains this same class qualifier and the class loader is trying to pick it up from there and not the target directory as specified in the debug build path? How do I find from where the class loader is attempting to load a class, e.g. file system path looking for a .class file or some jar?

preguntado el 09 de septiembre de 13 a las 20:09

1 Respuestas

Look at the file in the Eclipse "Package Explorer" view. That may give you some help. Also, you say that the .class file is in the target directory, but what about the source .java file?

Other things to check are the Java Build Path of your project properties.

I hope this helps, though you didn't really give enough detail to be able to understand what's really going on.

Respondido el 09 de Septiembre de 13 a las 21:09

ambas .java y .class files are where they are supposed to be - anfibio

Sorry, I'd missed the part about the two classes being in the same package but in different directories. In that case, my answer is probably moot, though I'd still suggest taking another look at the project's Build Path. You can also check the timestamp on ProblemClass.class to make sure it actually is being built. Are you running this through the Eclipse Debugger? What about when you run it normally, does it work then, or do you have the same issue? - Menajem

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.