Scala repl throws error

JavaScalaRead Eval-Print-Loop

Java Problem Overview


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

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 enter and type println("hello, world"), it again throws this

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.04 and java -version gives

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)

Java Solutions


Solution 1 - Java

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.

This duplicate question contains exact instructions on ubuntu's java downgrade.

Solution 2 - Java

remove the scala 2.9.2 using terminal

 sudo apt-get remove scala 

download the latest scala from scala website

Installation instruction are giving on this link

Solution 3 - Java

You might have to run it with JDK 7 or 6

Solution 4 - Java

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionajayView Question on Stackoverflow
Solution 1 - Javaom-nom-nomView Answer on Stackoverflow
Solution 2 - JavaHafiz Shehbaz AliView Answer on Stackoverflow
Solution 3 - JavaRakesh SharmaView Answer on Stackoverflow
Solution 4 - JavaSabiView Answer on Stackoverflow