3
我在使用Scala處理我的處理項目。空指針異常:java類的標量擴展
我從延伸的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()'中。 – bjz
請添加您的答案,然後接受它:-) – aishwarya
我已經嘗試過;)。我沒有足夠的積分,所以我只能再回答6個小時。 – bjz