声明变量时的NoSuchMethodError

tol*_*gap 4 scala exception

使用Spark和Scala时,我遇到了一个奇怪的错误.我有一段声明变量的代码:

var offset = 0
Run Code Online (Sandbox Code Playgroud)

这会导致以下异常:

java.lang.NoSuchMethodError: scala.runtime.IntRef.create(I)Lscala/runtime/IntRef;
   at my.package.MyClass$class.myMethod(MyClass.scala:5)
   ...
Run Code Online (Sandbox Code Playgroud)

它直接指向变量声明.我正在使用Scala 2.11.2.编译工作.这是运行时错误.运行时,我没有得到任何依赖/版本不匹配警告sbt package.

Rég*_*les 12

这几乎可以肯定是scala版本不匹配.比较v2.10和v2.11中IntRef的定义,你可以看到create只在后一版本中引入(参见https://github.com/scala/scala/blob/v2.10.4/src/library/scala /runtime/IntRef.javahttps://github.com/scala/scala/blob/v2.11.0/src/library/scala/runtime/IntRef.java).你可以打赌,你的一些依赖项是根据scala版本<2.11.0编译的.您可能想尝试使用sbt-dependency-graph(https://github.com/jrudolph/sbt-dependency-graph)来检查传递依赖性.