Error not found value context?
Asked Answered
G

3

6
def join(username: String): scala.concurrent.Future[(Iteratee[JsValue, _], Enumerator[JsValue])] = {
  println("friend name in model" + username)
  val first = Akka.system.actorOf(Props[ChatRoom2], name = username)
  println("this is chat room two default")
}    

and when i use this val first = context.actorOf(Props[ChatRoom2],name=username)

I am use this for create a child actor in a different chat room but it shows an error not found value context.

Ger answered 3/4, 2014 at 7:28 Comment(0)
I
1

import akka.actor

Refer this url https://groups.google.com/forum/#!msg/akka-user/4eYJWKWhAe8/TTAIOAI-uaIJ

Ingeborgingelbert answered 3/4, 2014 at 10:6 Comment(4)
Check if you extends Actor class to your classIngeborgingelbert
Yes i extends Actor class in my class and i also have an object of this class in which i use this join code.Ger
I agree with @SKarthik's comment. Do you mean, you extend Actor class on ChatRoom2 or on the class having join method above?Wilmoth
Yes i extends Actor class on my class ChatRoom2.Ger
W
3

You cannot access actor context from a class not extending Actor. You must be extending Actor in the class having join method above (not only ChatRoom2)

Wilmoth answered 4/4, 2014 at 6:25 Comment(0)
G
3

When you use an actor system reference, you're creating "top level" actors, whereas using context creates "child actors" of your current actor. This means that accessing context only makes sense from within an Actor.

Here's an example:

val system = ActorSystem("name")
val act = system.actorOf(classOf[SomeActor])

class SomeActor extends Actor {
  def receive = {
    case _ => val child = context.actorOf(...)
  }
}

In this example "act" is a "top level" actor, and "child" is a child of "act", because it was created by act's context.

I hope this helps!

For more help please refer to the docs: http://doc.akka.io/docs/akka/2.3.1/scala/actors.html

Garges answered 7/4, 2014 at 15:2 Comment(0)
I
1

import akka.actor

Refer this url https://groups.google.com/forum/#!msg/akka-user/4eYJWKWhAe8/TTAIOAI-uaIJ

Ingeborgingelbert answered 3/4, 2014 at 10:6 Comment(4)
Check if you extends Actor class to your classIngeborgingelbert
Yes i extends Actor class in my class and i also have an object of this class in which i use this join code.Ger
I agree with @SKarthik's comment. Do you mean, you extend Actor class on ChatRoom2 or on the class having join method above?Wilmoth
Yes i extends Actor class on my class ChatRoom2.Ger

© 2022 - 2024 — McMap. All rights reserved.