Java Scala repl 抛出错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24517761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 12:42:14  来源:igfitidea点击:

Scala repl throws error

javascalaread-eval-print-loop

提问by ajay

When I type scalaon the terminal to start the repl, it throws this error

当我scala在终端上键入以启动 repl 时,它会引发此错误

scala> [init] error: error while loading AnnotatedElement, 
class file '/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar
(java/lang/reflect/AnnotatedElement.class)' 
is broken (bad constant pool tag 15 at byte 2713)

When I hit enterand type println("hello, world"), it again throws this

当我点击enter并输入时println("hello, world"),它再次抛出这个

error: error while loading CharSequence, 
class file '/usr/lib/jvm/java-8-oracle/jre/lib/rt.jar
(java/lang/CharSequence.class)' is broken
(bad constant pool tag 15 at byte 1501)

I am using Ubuntu 14.04and java -versiongives

我正在使用Ubuntu 14.04java -version提供

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

采纳答案by om-nom-nom

Either update to a newer scala version (2.10.3+) or downgrade java to java 6/7. As you have seen in the output, 2.9.2 was here long before java 8 was introduced (Copyright 2002-2011, LAMP/EPFL), so they don't work well together.

更新到较新的 scala 版本 (2.10.3+) 或将 java 降级到 java 6/7。正如您在输出中看到的,2.9.2 早在引入 Java 8 之前就已经存在 ( Copyright 2002-2011, LAMP/EPFL),因此它们不能很好地协同工作。

This duplicate questioncontains exact instructions on ubuntu's java downgrade.

这个重复的问题包含有关 ubuntu 的 java 降级的确切说明。

回答by Rakesh Sharma

You might have to run it with JDK 7 or 6

您可能必须使用 JDK 7 或 6 运行它

回答by Hafiz Shehbaz Ali

remove the scala 2.9.2 using terminal

使用终端删除 scala 2.9.2

 sudo apt-get remove scala 

download the latest scala from scala website

Scala 网站下载最新的 Scala

Installation instruction are giving on this link

安装说明在这个链接上给出

回答by Sabi

Downgrading JDK version to 7 solved this issue for me. Here is the solution: https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher

将 JDK 版本降级到 7 为我解决了这个问题。这是解决方案:https: //askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher