title: How to start a Scala akka actor
body: <p>Below class is causing an error at line new HelloWorld : </p>
  
  <pre><code>Exception in thread "main" akka.actor.ActorInitializationException: You cannot create an instance of [HelloWorld] 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:219)
    at akka.actor.Actor$class.$init$(Actor.scala:436)
    at HelloWorld.&lt;init&gt;(HelloWorld.scala:4)
    at Driver$.main(HelloWorld.scala:38)
    at Driver.main(HelloWorld.scala)
  </code></pre>
  
  <p>So I try  :  <code>val hw = actorOf(new HelloWorld)</code>
  But this causes a compiler error : </p>
  
  <pre><code>not found: value actorOf
  </code></pre>
  
  <p>How should HelloWorld below be implemented ?</p>
  
  <p>Reading other Scala docs an act method is requried to be defined within the class that extends Actor and then invoke the start method on this class, is there a reason for using actorOf instead of defining an act method ?</p>
  
  <p>Below class is taken from Scala akka docs <a href="http://doc.akka.io/docs/akka/2.2.0/scala.html" rel="noreferrer">http://doc.akka.io/docs/akka/2.2.0/scala.html</a> : </p>
  
  <pre><code>import akka.actor.Actor
  import akka.actor.Actor._
  import akka.actor.Props
  
  class HelloWorld extends Actor {
  
    override def preStart(): Unit = {
      // create the greeter actor
      val greeter = context.actorOf(Props[Greeter], "greeter")
      // tell it to perform the greeting
      greeter ! Greeter.Greet
    }
    def receive = {
      // when the greeter is done, stop this actor and with it the application
      case Greeter.Done =&gt; context.stop(self)
    }
  
    object Greeter {   
  
      case object Greet
      case object Done
  
  
    }
    class Greeter extends Actor {
      def receive = {
        case Greeter.Greet =&gt;
          println("Hello World!")
          sender ! Greeter.Done
      }
    }
  
  
  }
  
  object Driver {
  
      def main(args: Array[String]) {
        new HelloWorld
      }
  
  }
  </code></pre>