zoukankan      html  css  js  c++  java
  • akka创建actor时报错:IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$

    在spark-shell中输入范例中的代码:

    import akka.actor.Actor
    import akka.actor.Props
    import akka.event.Logging
     
    class MyActor extends Actor {
      val log = Logging(context.system, this)
      def receive = {
        case "test" ⇒ log.info("received test")
        case _      ⇒ log.info("received unknown message")
      }
    }
    
    val system = ActorSystem("MySystem")
      val myActor = system.actorOf(Props[MyActor], name = "myactor")

    结果总是遇到如下错误:

    scala>   val myActor = system.actorOf(Props[MyActor], name = "myactor")
    java.lang.IllegalArgumentException: no matching constructor found on class $iwC$$iwC$$iwC$$iwC$MyActor for arguments []
    	at akka.util.Reflect$.error$1(Reflect.scala:81)
    	at akka.util.Reflect$.findConstructor(Reflect.scala:93)
    	at akka.actor.Props.constructor(Props.scala:194)
    	at akka.actor.Props.<init>(Props.scala:213)
    	at akka.actor.Props$.apply(Props.scala:69)
    	at $iwC$$iwC$$iwC$$iwC$$iwC$$iwC$$iwC.<init>(<console>:24)

    百思不得其解!最后终于找到了原因:不能采用内嵌类作为actor类!!!!spark-shell里面的类会被认为是内嵌类,为了避免以上错误,需要单独写类文件。

    stackoverflow里面是这么解释的:

    Take this example:

    class A{
      class B{}
    }

    I can do new A, but new B will return an error. I have to do:

    val a = new A
    val b = new a.B

    That's why akka failed to create this actor.



  • 相关阅读:
    N皇后
    逆波兰中缀转后缀代码
    ImportError: No module named Image
    稳定排序 和 不稳定排序 ::::::::::: 内排序和外排序
    逆波兰中 中缀表达式转后缀表达式的方法
    第一章:Unix基础知识
    软件设计流程
    linux 下 tar.xz 文件的解压方法
    fedora 解决 Python.h:没有那个文件或目录 错误的方法
    Shell排序
  • 原文地址:https://www.cnblogs.com/bluejoe/p/5115841.html
Copyright © 2011-2022 走看看