Home > Blockchain >  I can't import the class whose path is IDEA's source root file
I can't import the class whose path is IDEA's source root file

Time:03-28

Software: IntelliJ IDEA
OS: Ubuntu20.04.3 LST
Language: Scala Chisel

Here is my project path tree:

- src[sources root]
-- common
--- Extend.scala
-- NpcCore.scala

Extend.scala

package common

class Extend extends NpcCore{
    ...
}

I want to import NpcCore, but I can't add package src in NpcCore.scala, it will prompt Package name 'src' does not correspond to the file path ''.

Now I can only solve this problem by adding a package npc and moving NpcCore.scala.Is there a solution if I don't move NpcCore.scala?

CodePudding user response:

There is no way to import the class if you don't move it to a package. However, packages exist for good reason, as they prevent naming collisons which would be otherwise be unavoidable once your project grows and you start using libraries. Without exception, structuring your code in a proper package hierarchy is a best practice that I'd recommend you follow from the get go.

  • Related