0

I have a main object in akka.

object Application extends App {
  val system = ActorSystem()
  //...............
}

When I run it, it throws an exception of

Exception in thread "main" java.lang.NoSuchMethodError: akka.actor.ActorSystem.dispatcher()Lscala/concurrent/ExecutionContext;

How do I get rid of it?

I'm using akka 2.2.0

Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
  • I think it's a problem with Akka 2.1. Are you on 2.1 or 2.2? – Harshal Pandya Jul 30 '13 at 04:41
  • @HarshalPandya, that's 2.2.0 – Alan Coromano Jul 30 '13 at 04:45
  • may be duplicated with [this][1], hope it helps [1]: http://stackoverflow.com/questions/17890223/akka-scheduler-throws-exceptions-only-in-microkernel-but-works-fine-in-eclipse-i – Septem Jul 30 '13 at 06:19
  • Which version of scala are you using? Akka 2.2.0 should be run with scala 2.10.+. If you somehow are trying to run it with scala 2.9 (by example) you are bound to have those kinds of errors as `scala.concurrent.ExecutionContext` was only added in scala 2.10.0. – Régis Jean-Gilles Jul 30 '13 at 07:48
  • @RégisJean-Gilles, scala 2.10 – Alan Coromano Jul 30 '13 at 08:35
  • My bad, looking again at the error it is obvious that the problem is not with the scala version, but rather with the fact that some part of your code (or dependency) expects akka version 2.2.0 (where `ActorSystem.dispatcher` returns an `ExecutionContext`) but you have actually loaded an earlier version (this method used to return a `MessageDispatcher`). There is a high chance that you have two different versions of akka in your classpath. By example some of your dependencies might load akka 2.1.4, while your code links again akka 2.2.0. Check all your transitive dependencies. – Régis Jean-Gilles Jul 30 '13 at 09:23
  • @RégisJean-Gilles, I'm using akka 2.2.0 – Alan Coromano Jul 30 '13 at 12:10
  • I understand that. The question is: what other dependencies does your application have? Chances are that one of them has a dependency to another version of akka, and thus you are getting this other version (transitively) in your classpath. – Régis Jean-Gilles Jul 30 '13 at 12:56
  • @RégisJean-Gilles, do you mean build.sbt? I updated my question. – Alan Coromano Jul 30 '13 at 15:08

1 Answers1

2

Now that you have updated your answer with your "build.sbt" file, it is rather clear what is happening: your application has "org.scalaj" % "scalaj-http_2.9.2" % "0.3.7" as a dependency. You are forcing the scala version for "scalaj", meaning that you will (transitively) get scala 2.9.2 pulled in your classpath, in addition to scala 2.10.2. To avoid this, do not force the scala version in your dependencies, but let sbt infer it from your project's scala version, by using the %% operator instead of % (just like you did for your other dependencies):

"org.scalaj" %% "scalaj-http" % "0.3.9"

Note that I have upgraded the library version to 0.3.9 as it is apparently the first version to be available for scala 2.10.

Régis Jean-Gilles
  • 32,541
  • 5
  • 83
  • 97