Import class from parent package in Java

Mocoro :

I suspect I misunderstood some basic concept of packages in Java. Here is my hierarchy of the project:

  • Application (class with main)
  • Option (class)
  • Algorithm (Package)
    • PreProcessOptions (class)
    • GenerateImage (class)

Now, I would like that PreProcessOptions class will use Option class, to get all necessary data, but my IDE cannot find the class.

Any explanations? Thanks.

Pirate :

Create a structure like this.

src
 -> main
     -> Application (class with main)
     -> Option (class)
 -> Algorithm (Package)
     -> PreProcessOptions (class)
     -> GenerateImage (class)

Now in your PreProcessOption class import the main package.

package Algorithm;
import main.Option;

Hope this will help.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=217295&siteId=1