title: Scala Hello World: NoSuchMethodError: java.nio.ByteBuffer.clear
body: <p>When I try to compile a simple hello world program in Scala:</p>
  
  <p><code>Hello.scala</code>:</p>
  
  <pre><code>object Hello {
      def main(args: Array[String]): Unit = {
          println("hello world")
      }
  }
  </code></pre>
  
  <p>with <code>scalac Hello.scala</code>. I get</p>
  
  <pre><code>error: java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:61)
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:40)
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:49)
          at scala.tools.nsc.Global.getSourceFile(Global.scala:395)
          at scala.tools.nsc.Global.getSourceFile(Global.scala:401)
          at scala.tools.nsc.Global$Run$$anonfun$30.apply(Global.scala:1607)
          at scala.tools.nsc.Global$Run$$anonfun$30.apply(Global.scala:1607)
          at scala.collection.immutable.List.map(List.scala:284)
          at scala.tools.nsc.Global$Run.compile(Global.scala:1607)
          at scala.tools.nsc.Driver.doCompile(Driver.scala:32)
          at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
          at scala.tools.nsc.Driver.process(Driver.scala:51)
          at scala.tools.nsc.Driver.main(Driver.scala:64)
          at scala.tools.nsc.Main.main(Main.scala)
  Exception in thread "main" java.lang.NoSuchMethodError: java.nio.ByteBuffer.clear()Ljava/nio/ByteBuffer;
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:61)
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:40)
          at scala.tools.nsc.io.SourceReader.read(SourceReader.scala:49)
          at scala.tools.nsc.Global.getSourceFile(Global.scala:395)
          at scala.tools.nsc.Global.getSourceFile(Global.scala:401)
          at scala.tools.nsc.Global$Run$$anonfun$30.apply(Global.scala:1607)
          at scala.tools.nsc.Global$Run$$anonfun$30.apply(Global.scala:1607)
          at scala.collection.immutable.List.map(List.scala:284)
          at scala.tools.nsc.Global$Run.compile(Global.scala:1607)
          at scala.tools.nsc.Driver.doCompile(Driver.scala:32)
          at scala.tools.nsc.MainClass.doCompile(Main.scala:23)
          at scala.tools.nsc.Driver.process(Driver.scala:51)
          at scala.tools.nsc.Driver.main(Driver.scala:64)
          at scala.tools.nsc.Main.main(Main.scala)
  </code></pre>
  
  <p>on Ubuntu 18 with <code>scalac</code> version <code>2.11.12</code> and java version <code>1.8.0_181</code>. Strangely, this same program will compile and run on macOS with <code>scalac</code> version <code>2.12.6</code> and java <code>1.8.0_111</code>.</p>
  
  <p>My two questions are: why does this happen? How can I fix this?</p>
  
  <p>Thank you.</p>