0
В Актере я создаю ребенок актер, как показано нижеОшибка при создании ребенка актер
ActorRef sessionEventHandlerActor = getContext().actorOf(Props.create(SessionHandler.class), sessionId);
и это SessionHandler актер:
public class SessionHandler extends UntypedActor {
public SessionHandler() {
getContext().setReceiveTimeout(Duration.create(1, TimeUnit.MINUTES));
}
@Override
public void onReceive(Object message) throws Exception {
}
}
и я получаю следующее сообщение об ошибке:
Caused by: akka.actor.ActorInitializationException: You cannot create an instance of [actors.SessionHandler] explicitly using the constructor (new). You have to use one of the 'actorOf' factory methods to create a new actor. See the documentation.
at akka.actor.ActorInitializationException$.apply(Actor.scala:165)
at akka.actor.Actor$class.$init$(Actor.scala:421)
at akka.actor.UntypedActor.<init>(UntypedActor.scala:97)
at org.esi.actors.SessionHandler.<init>(SessionHandler.java:22)
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:422)
at java.lang.Class.newInstance(Class.java:442)
at akka.util.Reflect$.instantiate(Reflect.scala:45)
at akka.actor.NoArgsReflectConstructor.produce(Props.scala:358)
at akka.actor.Props.newActor(Props.scala:249)
at akka.actor.ActorCell.newActor(ActorCell.scala:552)
at akka.actor.ActorCell.create(ActorCell.scala:578)
Я не вижу никакой проблемы в том, как я создаю актера. Кто-нибудь знает, в чем проблема?
Спасибо
Взгляните на этот вопрос: http://stackoverflow.com/questions/10735716/unable-to-create-an-actor-using-untypedactorfactory-of-akka-java-api –
@BranislavLazic Спасибо, но как вы видите в моем коде, я не создаю _actor вне ActorSystem: getContext(). actorOf (Props.create (SessionHandler.class), «name»); _ – sansari
Какая строка (22) является исключением? – thwiegan