I am new to Scala. Could you help me with a problem I am having when executing a Scala class from the command line.
Executing the code below in Eclipse I get the expected result, i.e. “hello” printed 10 times. However, when I execute from the command line, using scala testArray from the directory containing the file testArray.class then I get an exception
java.lang.NoClassDefFoundError: scala/runtime/RichInt$
at TestArray$.main(TestArray.scala:3)
at TestArray.main(TestArray.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
...
I have a Windows XP machine, with Java 1.6 installed. The Scala bin directory is included in the PATH and the Scala directory is set as SCALA_HOME. I am using Scala 2.9.2.
The complete source:
object TestArray {
def main(args: Array[String]): Unit = {
var index: Int = 10
for (index <- 0 until 10) {
println("hello")
}
}
}
After checking the source executed OK in the interpreter and then compiling outside Eclipse using scalac and also executing OK I gathered the Eclipse part must be at fault. Indeed I uninstalled scala from Eclipse and reinstalled from the nightly build and now the created class executes with no problem.