Search code examples
javaeclipsejarbuildpath.class-file

Adding .class files to the build path in Eclipse


I'm trying to add the SOS.class file to the build path, however, I'm not quite succeeded. I tried converting and adding this SOS.class file as SOS.jar file, yet, It didn't worked again.

When I declare the class's object reference it just gives me this error:

**Error**

I added my files through:

Right Click to project>BuildPath>Configure Build Path>Libraries>Add External Class Folder

This is my folder structure:

**Folder Structure**

My SOS.class file is located in desktop, inside Classes folder.

Thank you in advance!


Solution

  • The problem is that you're accessing a class in the default package from within a class that has a package (partB). This is not allowed in Java (see this bug). You have to either get SOS.class moved to a non-default package, or only access from another class without a package.