声明变量时出现NoSuchMethodError [英] NoSuchMethodError when declaring a variable

查看:118
本文介绍了声明变量时出现NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm running into a weird error when using Spark and Scala. I have a piece of code that declares a variable:

var offset = 0

这会导致以下异常:

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

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

And it points directly at the variable declaration. I am using Scala 2.11.2. Compiling works. This is a runtime error. I do not get any dependency/version mismatch warnings when running sbt package either.

推荐答案

几乎可以肯定这是scala版本不匹配。
比较v2.10和v2.11中IntRef的定义,您可以看到 create 仅在后一个版本中引入(请参见https://github.com/scala/scala/blob/v2.10.4/src /library/scala/runtime/IntRef.java https://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 )来检查您的传递依存关系。

This is almost certainly a scala version mismatch. Comparing the definition of IntRef in v2.10 and v2.11, you can see that create was only introduced in the latter version (see https://github.com/scala/scala/blob/v2.10.4/src/library/scala/runtime/IntRef.java and https://github.com/scala/scala/blob/v2.11.0/src/library/scala/runtime/IntRef.java). You can bet that some of your dependencies was compiled against a scala version < 2.11.0. You might want to try sbt-dependency-graph (https://github.com/jrudolph/sbt-dependency-graph) to check your transitive dependencies.

这篇关于声明变量时出现NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆