akka中的Actor创建错误

时间:2013-10-26 22:58:57

标签: scala akka

尝试在akka中创建一个actor并调用其receive函数。我一直收到这个错误。

[ERROR] [10/26/2013 18:53:29.313] [messagespreading-akka.actor.default-dispatcher-4] [akka://messagespreading/user/$a] error while processing Create(-1187846526)
70ec3d6a-184d-403c-8166-04aec76200c9akka.actor.ActorInitializationException: exception during creation
    at akka.actor.ActorInitializationException$.apply(Actor.scala:169)
    at akka.actor.ActorCell.create(ActorCell.scala:496)
    at akka.actor.ActorCell.systemInvoke(ActorCell.scala:351)
    at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:256)
    at akka.dispatch.Mailbox.run(Mailbox.scala:211)
    at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:502)
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
    at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
    at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)
Caused by: java.lang.IllegalArgumentException: n must be positive
    at java.util.Random.nextInt(Random.java:250)
    at scala.util.Random.nextInt(Random.scala:65)
    at NetworkBuilder.<init>(pastry.scala:431)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at java.lang.Class.newInstance0(Class.java:357)
    at java.lang.Class.newInstance(Class.java:310)
    at akka.util.Reflect$.instantiate(Reflect.scala:39)
    at akka.actor.FromClassCreator.apply(Props.scala:187)
    at akka.actor.FromClassCreator.apply(Props.scala:186)
    at akka.actor.ActorCell.newActor(ActorCell.scala:461)
    at akka.actor.ActorCell.create(ActorCell.scala:479)
    ... 8 more

创建并致电ACTOR接收的代码。

val system = ActorSystem("messagespreading")
var NetworkBuilderObj:ActorRef= system.actorOf(Props[NetworkBuilder]) 
NetworkBuilderObj ! test

1 个答案:

答案 0 :(得分:5)

当您在第三方代码中发生异常时,您需要查看是否存在Caused by。在这种情况下,它说

Caused by: java.lang.IllegalArgumentException: n must be positive
 at java.util.Random.nextInt(Random.java:250)
 at scala.util.Random.nextInt(Random.scala:65)
 at NetworkBuilder.(pastry.scala:431)

所以有错误 - 它与您发布的代码无关。