【发布时间】:2011-12-24 03:21:11
【问题描述】:
我正在尝试将 Scala 用于我的处理项目。
我已经从 ToxicLibs 扩展了 Rect 类,但是当我尝试从方法中调用 rect(toxi.geom.Rect r) 时遇到空指针异常。
import toxi.processing.ToxiclibsSupport
import toxi.geom.{ Vec2D, Rect }
class Scope(x: Float, y: Float, width: Float, height: Float) extends Rect(x, y, width, height) {
def this(r: Rect) {
this(r.x, r.y, r.width, r.height)
}
def draw(gfx: ToxiclibsSupport) {
gfx.rect(this) // null pointer exception occurs here
}
}
这是调用draw方法的代码:
import processing.core.PApplet
import toxi.processing.ToxiclibsSupport
import toxi.geom.Rect
class ScalaP5Test extends PApplet {
var gfx = new ToxiclibsSupport(this)
override def setup() {
size(1000, 800)
}
override def draw() {
var scope = new Scope(100, 200, 400, 300)
scope.draw(gfx) // draw called here
}
}
有什么想法吗?
【问题讨论】:
-
啊,我明白了。我将 gfx 初始化更改为:
var gfx: ToxiclibsSupport = null并将gfx = new ToxiclibsSupport(this)添加到setup()。 -
请添加您的答案并接受它然后:-)
-
我已经试过了;)。我没有足够的积分,所以我要再等 6 个小时才能回答自己。
标签: java scala nullpointerexception processing