error: not found: value ...
error: not found: value ...
DodaTech
3 min read
The “not found: value” error means the Scala compiler cannot resolve an identifier — a variable, function, or object — at the current position in your code.
What It Means
Scala resolves every identifier against the current scope: local declarations, enclosing class members, imports, and top-level definitions in the same package. When a name doesn’t match any visible declaration, the compiler reports “not found: value [name].” Unlike dynamic languages, this is a compile-time error — the program cannot run until every identifier is resolved.
Why It Happens
- You mistyped a variable or function name (Scala is case-sensitive).
- A variable or function was declared in a different scope and is not accessible.
- An
importstatement is missing for a definition in another package. - You used the wrong case —
MyObjectvsmyObject. - The definition is declared later in the same scope (Scala resolves top-down in blocks).
- A library or object is not on the classpath (missing dependency).
How to Fix It
1. Check for typos and case
// ❌ not found: value helloworld
val helloWorld = "Hello"
println(helloworld)
// ✅ Match the declaration exactly
println(helloWorld)2. Fix import statements
// ❌ not found: value File
def readFile(path: String): String = File(path).read()
// ✅ Add the required import
import scala.io.Source
def readFile(path: String): String = Source.fromFile(path).mkString3. Check variable scope
// ❌ not found: value result
def process(): Unit = {
if (true) {
val result = 42
}
println(result) // result is out of scope here
}
// ✅ Declare before the block
def process(): Unit = {
val result = if (true) 42 else 0
println(result)
}4. Verify package paths for objects and companions
// File: com/example/utils/Helpers.scala
package com.example.utils
object Helpers {
def greet(name: String): String = s"Hello, $name!"
}
// File: Main.scala
// ❌ not found: value Helpers
object Main extends App {
println(Helpers.greet("World"))
}
// ✅ Import the object
import com.example.utils.Helpers
object Main extends App {
println(Helpers.greet("World"))
}5. Add missing dependencies in build.sbt
If the value comes from an external library:
// build.sbt
// ❌ not found: value Circe (or any library type)
libraryDependencies += "io.circe" %% "circe-core" % "0.14.7"After adding, run sbt update to fetch the dependency.
6. Use the correct object name for standard library methods
// ❌ not found: value readLine (moved or renamed in Scala 2.13+)
val input = readLine()
// ✅ Use scala.io.StdIn
import scala.io.StdIn
val input = StdIn.readLine() Previous
ERROR 1146 (42S02): Table '...' doesn't exist
Next
ERROR: relation 'table_name' does not exist
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro