格式化一个简单的字符串,但是`java.lang.NoSuchMethodError`

时间:2012-10-27 19:20:31

标签: scala string-formatting

我正在使用Scala 2.9.2。

运行Scala并测试一个简单的代码,这段代码是......好的:

...
val title = "Hashing file (%s)..." format sizeToStr(file.length)

但是我无法理解什么是什么,而我将该代码放入一个简单的应用程序中,编译好了,在运行时它抛出了这个:

java.lang.NoSuchMethodError: scala.Predef$.augmentString(Ljava/lang/String;)Lscala/collection/immutable/StringOps;
        at group.pals.penguin.app.shasher.Shasher$.calcHash(shasher.scala:119)
        at group.pals.penguin.app.shasher.Shasher$.main(shasher.scala:76)
        at group.pals.penguin.app.shasher.Shasher.main(shasher.scala)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:601)
        at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:71)
        at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:31)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:139)
        at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:71)
        at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:139)
        at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
        at scala.tools.nsc.JarRunner$.run(MainGenericRunner.scala:16)
        at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
        at scala.tools.nsc.JarRunner$.runAndCatch(MainGenericRunner.scala:16)
        at scala.tools.nsc.JarRunner$.runJar(MainGenericRunner.scala:28)
        at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:78)
        at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:96)
        at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:105)
        at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala)
你可以帮帮我吗?感谢。

1 个答案:

答案 0 :(得分:12)

您似乎正在编译标准库的不同版本而不是在运行时使用。