gpt4 book ai didi

r - 使用 rscala 在 R 中使用 Scala 时出现 NoSuchMethodError

转载 作者:行者123 更新时间:2023-12-04 15:06:10 24 4
gpt4 key购买 nike

我在 R 中使用 rscala 包调用预编译的 Scala 代码时遇到问题。

我有一个在版本 2.11.12 上运行的 Scala 项目.我用 sbt-assembly 构建了一个 fat jar 子,并通过 rscala::scala("path-to-jar.jar") 将其提供给 rscala

但是每当我尝试从包中运行任何函数/方法/任何东西时,我都会收到以下错误:

java.lang.reflect.InvocationTargetException
java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
at myPackage.myClass$.myMethod(myClass.scala:116)
at $line6.$read$$iw$$iw$$iw$$iw$.$anonfun$res0$1(<console>:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.ddahl.rscala.server.Server.$anonfun$invoke$3(Server.scala:305)
at org.ddahl.rscala.server.Server.wrap(Server.scala:47)
at org.ddahl.rscala.server.Server.invoke(Server.scala:305)
at org.ddahl.rscala.server.Server.run(Server.scala:400)
at org.ddahl.rscala.server.Main$.delayedEndpoint$org$ddahl$rscala$server$Main$1(Main.scala:105)
at org.ddahl.rscala.server.Main$delayedInit$body.apply(Main.scala:11)
at scala.Function0.apply$mcV$sp(Function0.scala:39)
at scala.Function0.apply$mcV$sp$(Function0.scala:39)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:17)
at scala.App.$anonfun$main$1$adapted(App.scala:80)
at scala.collection.immutable.List.foreach(List.scala:392)
at scala.App.main(App.scala:80)
at scala.App.main$(App.scala:78)
at org.ddahl.rscala.server.Main$.main(Main.scala:11)
at org.ddahl.rscala.server.Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at scala.reflect.internal.util.ScalaClassLoader.$anonfun$run$2(ScalaClassLoader.scala:106)
at scala.reflect.internal.util.ScalaClassLoader.asContext(ScalaClassLoader.scala:41)
at scala.reflect.internal.util.ScalaClassLoader.asContext$(ScalaClassLoader.scala:37)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:132)
at scala.reflect.internal.util.ScalaClassLoader.run(ScalaClassLoader.scala:106)
at scala.reflect.internal.util.ScalaClassLoader.run$(ScalaClassLoader.scala:98)
at scala.reflect.internal.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:132)
at scala.tools.nsc.CommonRunner.run(ObjectRunner.scala:28)
at scala.tools.nsc.CommonRunner.run$(ObjectRunner.scala:27)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
at scala.tools.nsc.CommonRunner.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.CommonRunner.runAndCatch$(ObjectRunner.scala:34)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:73)
at scala.tools.nsc.MainGenericRunner.run$1(MainGenericRunner.scala:92)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:103)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:108)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
Error in pop(details, transcompileInfo, envir) : Invocation error.

它确实允许我导入它的类和对象,所以它似乎确实在类路径中,但就是这样。

我的 build.sbt 包括 crossScalaVersions := Seq("2.11.12", "2.12.7", "2.13.0-M5")根据包装要求。

有什么想法吗?似乎是 Scala 版本错误,因为运行 rscala::scalaConfig()告诉我它正在使用 scalaFullVersion 2.12.8 ,但我似乎无法选择 scala 安装,所以我真的不能指望这是问题所在。

编辑:

在 Jasper-M 的建议之后,我设置了环境变量 RSCALA_SCALA_MAJORVERSION=2.11并使用 rscala::scalaConfig(download='scala') 重新执行配置.现在它返回 scalaMajorVersion2.11 .

现在,当我使用 rscala::scala() 创建 scala 桥的实例时,它返回一条消息(不是错误)说:
cat: /release: No such file or directory

如果我运行 println()它编译没有问题。但是,如果我使用自己的预编译胖 JAR 实例化 scala 桥并执行任何操作(例如 println ),它会返回以下错误:
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/reflect/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/reflect/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading package, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/package.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)
error: error while loading Predef, class file '$HOME/.rscala/scala/lib/scala-library.jar(scala/Predef.class)' is broken
(class java.lang.RuntimeException/Scala class file does not contain Scala annotation)

我在这里真的一窍不通。有任何想法吗?

最佳答案

这绝对是 Scala 版本错误。

我最好的猜测是你必须设置环境变量 RSCALA_SCALA_MAJORVERSION=2.11 .例如。通过调用

Sys.setenv(RSCALA_SCALA_MAJORVERSION = "2.11")

然后运行
rscala::scalaConfig(download = "scala")

关于r - 使用 rscala 在 R 中使用 Scala 时出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55818756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com