RemcoW RemcoW - 1 year ago 145
Scala Question

Akka cannot start ActorSystem

I've been following the QuickStart guide for Akka Streams and I'm running into an error. My code is simple:

object Main extends App {
implicit val system = ActorSystem("QuickStart")
implicit val materializer = ActorMaterializer()

val source: Source[Int, NotUsed] = Source(1 to 100)
source.runForeach(i => println(i)) (materializer)

However this results in an error:

Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class
at akka.util.Timeout.(Timeout.scala:13)
at streams_test.Main$.delayedEndpoint$streams_test$Main$1(Main.scala:14)
at streams_test.Main$delayedInit$body.apply(Main.scala:13)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App.$anonfun$main$1$adapted(App.scala:76)
at scala.collection.immutable.List.foreach(List.scala:378)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at streams_test.Main$.main(Main.scala:13)
at streams_test.Main.main(Main.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.lang.ClassLoader.loadClass(
at sun.misc.Launcher$AppClassLoader.loadClass(
at java.lang.ClassLoader.loadClass(
... 19 more

I've also tried running it through the sbt console with no luck. Does anyone know what's causing this issue? It is being throwed at the line:

implicit val system = ActorSystem("QuickStart")

As requested, my

name := "Akka_test"

version := "1.0"

scalaVersion := "2.12.0"

libraryDependencies += "com.typesafe.akka" % "akka-actor_2.11" % "2.3.9"
libraryDependencies += "com.typesafe.akka" % "akka-stream_2.11" % "2.4.12"
libraryDependencies += "org.twitter4j" % "twitter4j-core" % "4.0.2"

Answer Source

This could be the Scala version problem you might be using the 2.10 compiled library with 2.11 compiler or vice versa.

You can avoid running into the problem if you explicitly have scala version in build.sbt and use %% after groupId in build.sbt

use this

scalaVersion := "scala_version"

libraryDependencies += "group_id" %% "artificat_id" % "version"

instead of

libraryDependencies += "group_id" % "artificat_id_scala_version" % "version"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download