-1

I have the following code (note that I'm posting a photo instead of copy-pasting code because the project structure is also relevant):Code

I believe the error is because Seriallizer is in the io package and can't see GraphEditor. Howerver I've tried a lot of imports like import GraphEditor; import src.GraphEditor; import GraphEditor.src.GraphEditor but none worked and I reckon I'm missing something. Thank you!

Udar
  • 63
  • 1
  • 11
  • File structure looks fine to me. Have you tried to compile the code via the command line? Seems like a project setup issue. – Turing85 Jun 11 '20 at 13:55
  • It looks like your GraphEditor is in the "default" package, i.e. it doesn't have a package. Move it to a package and you should be able to import it (you will need to add the package statement to the file, and move it on the file system to achieve this) – Goibniu Jun 11 '20 at 13:59
  • Try using `src/main/java` as root for you classes – Ezequiel Jun 11 '20 at 14:02
  • @Turing85 I ve just tried to compile it with javac GraphEditor.java and it finds some errors but when running it in IntelliJ it works fine – Udar Jun 11 '20 at 14:08

2 Answers2

0

You can't import from the default package. See What's the syntax to import a class in a default package in Java?

The simplest thing to do here is to make sure everything has a package. Usually people create a root package for their project to avoid this problem.

Matthew
  • 10,361
  • 5
  • 42
  • 54
0

All import does is let you reference classes in your source without the package name

So for instance,

import java.io.InputStream

lets you create a variable

  InputStream myInputStream;

instead of having to use

  java.io.InputStream myInputStream;

Finally, it seems like GraphEditor doesn't have a package. I forget if/how you can reference other classes in the default domain space (i.e. no package), but if you gave it a package and moved it the the appropriate place in the file system, that might resolve your issue

ControlAltDel
  • 33,923
  • 10
  • 53
  • 80