Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I get java.lang.NoClassDefFoundError when I trying to run this code?

I want to map over the characters in a string, but I'm getting runtime errors.

Example:

object Hello {
    def hello(c: Char) {
        print(c)
    }

    def main(args: Array[String]) {
        "Hello World!".map(hello)
    }
}

Trace:

scalac Hello.scala
java Hello
Exception in thread "main" java.lang.NoClassDefFoundError: scala/LowPriorityImplicits
    at Hello.main(Hello.scala)
Caused by: java.lang.ClassNotFoundException: scala.LowPriorityImplicits
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 1 more
make: *** [test] Error 1
like image 926
mcandre Avatar asked Jan 19 '13 19:01

mcandre


People also ask

How do I fix Java Lang NoClassDefFoundError error?

lang. NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present.

What is exception in thread main Java Lang NoClassDefFoundError?

NoClassDefFoundError is a common error in Java that occurs if a ClassLoader cannot find a particular class in the classpath while trying to load it. The Exception in thread "main" suggests that this error has occurred in the main thread, the thread which is responsible for running the Java application.


1 Answers

I think that your problem is that scala library is not in your runtime classpath. you must manually add manually.

If you are using tools like maven or sbt, maybe the dependency is marked as provided instead compiled.

If you are not using these tools, add "scala-library.jar" to your library directory

like image 188
fhuertas Avatar answered Oct 22 '22 22:10

fhuertas