我的第一个actor01.scala如下:
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
class HelloActor extends Actor{
override def receive = {
case "hello" => println("hello received")
case _ => println("other messages")
}
}
object actor01 extends App{
val system = ActorSystem("actor01")
val helloActor = system.actorOf(Props[HelloActor],name="myActor")
helloActor!"msg"
helloActor!"hello"
}
我的pom.xml已经导入了akka:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.version>2.11</scala.version>
<scala.compat.version>2.11</scala.compat.version>
</properties>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_${scala.version}</artifactId>
<version>2.5.14</version>
</dependency>
因此,在intellij中,我编译并运行了该程序,我遇到了一堆异常。我想知道这是编码错误还是Maven存储库不匹配?
Exception in thread "main" java.lang.NoSuchMethodError: scala.Predef$.refArrayOps([Ljava/lang/Object;)Lscala/collection/mutable/ArrayOps;
at akka.actor.Deployer.deploy(Deployer.scala:163)
at akka.actor.Deployer$$anonfun$3.apply(Deployer.scala:147)
at akka.actor.Deployer$$anonfun$3.apply(Deployer.scala:147)
at scala.collection.mutable.ResizableArray.foreach(ResizableArray.scala:59)
at scala.collection.mutable.ResizableArray.foreach$(ResizableArray.scala:52)
at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
at akka.actor.Deployer.<init>(Deployer.scala:147)
at akka.actor.LocalActorRefProvider.<init>(ActorRefProvider.scala:492)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$2.apply(ReflectiveDynamicAccess.scala:33)
at scala.util.Try$.apply(Try.scala:209)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:28)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(ReflectiveDynamicAccess.scala:39)
at akka.actor.ReflectiveDynamicAccess$$anonfun$createInstanceFor$3.apply(ReflectiveDynamicAccess.scala:39)
at scala.util.Success.flatMap(Try.scala:247)
at akka.actor.ReflectiveDynamicAccess.createInstanceFor(ReflectiveDynamicAccess.scala:39)
at akka.actor.ActorSystemImpl.liftedTree1$1(ActorSystem.scala:776)
at akka.actor.ActorSystemImpl.<init>(ActorSystem.scala:769)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:246)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:289)
at akka.actor.ActorSystem$.apply(ActorSystem.scala:234)
at actor01$.delayedEndpoint$actor01$1(actor01.scala:13)
at actor01$delayedInit$body.apply(actor01.scala:12)
at scala.Function0.apply$mcV$sp(Function0.scala:34)
at scala.Function0.apply$mcV$sp$(Function0.scala:34)
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:389)
at scala.App.main(App.scala:76)
at scala.App.main$(App.scala:74)
at actor01$.main(actor01.scala:12)
at actor01.main(actor01.scala)
如何解决?