Re: Error when Actor definition is inside another Actor

107 views
Skip to first unread message

Arun Ramakrishnan

unread,
Feb 10, 2012, 8:55:25 PM2/10/12
to akka...@googlegroups.com
This is the 2.0-M4

On Fri, Feb 10, 2012 at 5:43 PM, Arun Ramakrishnan <sinchron...@gmail.com> wrote:
The following snipper throws the error below. But, if I move the TAct definition to outside, then this dosent happen. Might be a nube question. But, am curious why.

**********************************************************************************
object Supervisor1 extends App {

  class Master extends Actor {
    
class TAct extends Actor {  def receive = { case a: Any => }   }
    def receive = { case _:String => context.actorOf(Props[TAct]) ! "hell" }
    
  }
  
    val system = ActorSystem("Supervisor1System")
    val master = system.actorOf(Props[Master],name = "master")
    master ! ""
}

// Results in 
/*


[ERROR] [02/10/2012 15:56:49.583] [ForkJoinPool-1-worker-1] [akka://Supervisor1System/user/master/$a] error while creating actor
java.lang.InstantiationException: ak.Supervisor1$Master$TAct
at java.lang.Class.newInstance0(Class.java:340)
at java.lang.Class.newInstance(Class.java:308)
at akka.actor.Props$$anonfun$apply$1.apply(Props.scala:46)
at akka.actor.Props$$anonfun$apply$1.apply(Props.scala:46)
at akka.actor.ActorCell.newActor(ActorCell.scala:344)
at akka.actor.ActorCell.create$1(ActorCell.scala:361)
at akka.actor.ActorCell.systemInvoke(ActorCell.scala:448)
at akka.dispatch.Mailbox.processAllSystemMessages(Mailbox.scala:194)
at akka.dispatch.Mailbox.run(Mailbox.scala:163)
at akka.dispatch.ForkJoinExecutorConfigurator$MailboxExecutionTask.exec(AbstractDispatcher.scala:448)
at akka.jsr166y.ForkJoinTask.doExec(ForkJoinTask.java:268)
at akka.jsr166y.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:929)
at akka.jsr166y.ForkJoinPool.runWorker(ForkJoinPool.java:1303)
at akka.jsr166y.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:104)
*/

Arun Ramakrishnan

unread,
Feb 10, 2012, 8:43:17 PM2/10/12
to akka...@googlegroups.com

Patrik Nordwall

unread,
Feb 11, 2012, 2:41:01 AM2/11/12
to akka...@googlegroups.com
The reason is that Props[TAct] can not be used for inner classes. You must use Props(new TAct) for that case.

/Patrik
--
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To post to this group, send email to akka...@googlegroups.com.
To unsubscribe from this group, send email to akka-user+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/akka-user?hl=en.
Reply all
Reply to author
Forward
0 new messages