1

I downloaded the Scala IDE Linux - 64 bit For Scala 2.11.2 and am trying to run a Scala Test. Following is my code.

package ppg.experiment.gameofbusiness.engine

import org.scalatest.FlatSpec
import org.scalatest.Matchers

class DiceSpec extends FlatSpec with Matchers {

  "A dice" should "roll a value greater than zero" in {
    new Dice().roll > 0
  }
  it should "roll a value less than six" in {
    new Dice().roll < 7
  }
}

When I right click and run as Scala Test the following is printed on the console

WARNING: -p has been deprecated and will be reused for a different (but still very cool) purpose in ScalaTest 2.0. Please change all uses of -p to -R.
java.lang.reflect.InvocationTargetException
    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:606)
    at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher$.main(ScalaTestLauncher.scala:58)
    at scala.tools.eclipse.scalatest.launching.ScalaTestLauncher.main(ScalaTestLauncher.scala)
Caused by: java.lang.NoSuchMethodError: scala.collection.immutable.$colon$colon.hd$1()Ljava/lang/Object;
    at org.scalatest.tools.Runner$.argTooShort$1(Runner.scala:1515)
    at org.scalatest.tools.Runner$.parseReporterArgsIntoConfigurations(Runner.scala:1532)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:923)
    at org.scalatest.tools.Runner$.main(Runner.scala:860)
    at org.scalatest.tools.Runner.main(Runner.scala)
    ... 6 more

Can someone tell me how to solve this problem?

Can't Tell
  • 12,714
  • 9
  • 63
  • 91

1 Answers1

6

Check your classpath; in particular check that the version of scalatest you're depending on is compiled for scala 2.11, not 2.10.

lmm
  • 17,386
  • 3
  • 26
  • 37
  • You are a genius! But can you tell me how you figured it out? – Can't Tell Nov 02 '14 at 17:50
  • Just reading the stacktrace. A `NoSuchMethodError` always means that the class invoking the method that doesn't exist (in this case, `Runner$`) was compiled against a different version of the class where the method doesn't exist (in this case, `$colon$colon`). Then you can look up those classes and see they belong to scalatest and the scala standard library respectively. – lmm Nov 03 '14 at 00:09
  • BTW, the way to do that is to go to your Project and right click, then Properties>Scala Compiler>select appropriate scala compiler> apply> OK – grasshopper Feb 12 '15 at 20:09