-1

I have a scala project, but the imports don't work as designed. I tried everything here, but nothing seems to fix the issue. My project is as follows:

- src
  - main
    - scala
      - importtest
        ImportTest.scala
      Main.scala
build.sbt

Imported class:

#/src/main/scala/importtest/ImportTest.scala
package importtest

class ImportTest {
  def run(): Unit = {
    System.out.println("boo!")
  }
}

My main class is:

#/src/main/scala/Main.scala
import importtest.ImportTest

object Main {
  def main(): Unit = {
    val i = ImportTest()
  }
}

My SBT build is:

name := "ImportTest"

version := "0.1"

scalaVersion := "2.12.6"

When I try to build, I get:

Error:(5, 13) not found: value ImportTest
    val i = ImportTest()

What is going wrong here? Why can't I import the ImportTest class?

Also, not sure if this helps, but IntelliJ will autocomplete the package name, but it cant autocomplete the class within the package - it marks it as unresolved.

1

1 Answer 1

4

You are initializing ImportTest() as if it was a case class. Because its a regular class, you need to use "new". Change the initialization to:

val i = new ImportTest()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.