我有以下两个Groovy类:
Buzz.groovy :
import widgets.Fizz
class Buzz {
def WhistleFeather
def init = { servletContext ->
WhistleFeather.load()
println "WhistleFeather loaded."
}
def destroy = { }
}
WhistleFeather.groovy :
package net.me.myapp
import widgets.Fizz
public class WhistleFeather {
def navMenu
def load() {
println "Loading!"
}
}
当执行进入WhistleFeather.load()
方法调用时,我得到NullPointerException
。谁能明白为什么?
答案 0 :(得分:1)
WhistleFeather#load
是一个实例方法,而不是静态方法。可以使用new WhistleFeather().load(),
调用它,也可以将其转换为静态方法(static load() { ... }
)。