在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.

随机推荐

  1. python的动态与解释

    python是一门动态解释型语言.为了理解"动态"和"解释",前几天都在看<Python源码剖析>,以下是自己的一些总结. 先说解释,除开py2ex ...

  2. git ssh key for github

    第一:检查.ssh是否存在(ls -al ~/.ssh) $ ls -al ~/.ssh Lists the files in your .ssh directory, if they exist 第 ...

  3. 将树莓派Raspberry Pi设置为无线路由器(WiFi热点AP,RTL8188CUS芯片)

    http://wangye.org/blog/archives/845/ 最近又开始折腾起Raspberry Pi来了,因为某处上网需要锐捷拨号,于是我就想能不能让我的树莓派代劳,当然首先要将其改造为 ...

  4. kvm usb

  5. 关于JavaScripting API您不知道的5件事

    现在,许多 Java 开发人员都喜欢在 Java 平台中使用脚本语言,但是使用编译到 Java 字节码中的动态语言有时是不可行的.在某些情况中,直接编写一个 Java 应用程序的脚本 部分 或者在一个 ...

  6. A Tour of Go Methods and Interfaces

    The next group of slides covers methods and interfaces, the constructs that define objects and their ...

  7. 与IO相关的等待事件troubleshooting-系列9

    Buffer Cache与IO相关的等待事件: 这种等待事件的产生原因是包含DBWR进程和IO Slaves的Buffer Cache操作. 'db file parallel write' , 'd ...

  8. CSS构造颜色、背景与图像

    设定颜色 背景使用 图像使用 1.设定颜色 红色的几种合法定义;     #f00;     #ff0000;     Red;     Rgb(255,0,0);     Rgb(100%,0%,0 ...

  9. 按要求编写一个Java应用程序: (1)定义一个类,描述一个矩形,包含有长、宽两种属性,和计算面积方法。 (2)编写一个类,继承自矩形类,同时该类描述长方体,具有长、宽、高属性, 和计算体积的方法。 (3)编写一个测试类,对以上两个类进行测试,创建一个长方体,定义其长、 宽、高,输出其底面积和体积。

    package jvxing; public class Jvxing { //成员变量 private double width; private double chang; public doub ...

  10. Fixed theorems

    Banach Schauder Bourbaki-Kneser