4

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!

Burak.
  • 598
  • 7
  • 19
  • It seems the you have added `SOS.class` file successfully. Did you forget to import it when your are using it? – Razib Mar 30 '15 at 21:34
  • @Razib whenever I import, It still doesn't work, I couldn't understand why, I didn't wrote the .class file but it simply doesn't work. Is there any way to look how the import path is built? – Burak. Mar 30 '15 at 21:37
  • It's hard to answer without having access to SOS.class. Can you confirm there is no package for the class (ie, being in default package is correct). Also showing the line of code that causes the error could help. I presume it's something like `SOS sos = new SOS();`. – Always Learning Mar 30 '15 at 21:41
  • @stvcisco no it is actually `private SOS game;` I just declared the reference variable. I don't know whether it has internal packaging or not, but I expect that Eclipse should automatically see the import path and give it as a quick fix. – Burak. Mar 30 '15 at 22:01
  • How did you add SOS.class to your referenced libraries? Did you go to the "Java Build Path" page of properties, then the "Libraries" tab, and click the "Add Class Folder" button, then specify the desktop\Classes folder? – Always Learning Mar 30 '15 at 22:01
  • @stvcisco Like this `Java Build Path > Add External Class Folder > And I picked my Classes folder which resides in my Desktop` – Burak. Mar 30 '15 at 22:04
  • Try double clicking on SOS.class under Referenced Libaries and make sure the class itself is public. Even though you don't have the source, Eclipse should open the class file editor and let you see the structure. If the class was declared as private for example, that might explain the error. – Always Learning Mar 30 '15 at 22:07
  • @stvcisco Unfortunately it is public :( – Burak. Mar 30 '15 at 22:10
  • Is it possible that there are missing dependencies that the SOS class needs? Sometimes there are automatic classes (like SOS$blah.class). Though if that was the case I'd expect a different error. – Always Learning Mar 30 '15 at 22:11
  • Could there be a mismatch between the Java version SOS.class was compiled with and the version you're using? – Always Learning Mar 30 '15 at 22:12
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74144/discussion-between-stvcisco-and-verum-infiniti). – Always Learning Mar 30 '15 at 22:14
  • @stvcisco There is actually a case that I'm suspecting about, before this adding .class file thing, I had a project called `SOS` and also a class called `SOS.java` inside it. However, I had deleted the entire project before trying to add this `SOS.class` file(by the way this is something different, names just resembles). Can it cause indirectly, or do I need to delete anything more?(I also deleted its folder from my workspace). – Burak. Mar 30 '15 at 22:15

1 Answers1

1

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.

Always Learning
  • 5,510
  • 2
  • 17
  • 34