-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.

Logister
  • 1,852
  • 23
  • 26

1 Answers1

3

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()
Michael Yakobi
  • 1,030
  • 1
  • 11
  • 13