为什么groovy中存在MissingMethodException错误?

为什么groovy中存在MissingMethodException错误?,groovy,int,return,Groovy,Int,Return,我试过了 谢谢大家,当我试图执行代码时,遇到了下面的错误 Caught: groovy.lang.MissingMethodException: No signature of method: static Example.updateGlobalInteger() is applicable for argument types: (java.lang.Integer) values: [10] Possible solutions: updateGlobalInteger(java.lang

我试过了

谢谢大家,当我试图执行代码时,遇到了下面的错误

Caught: groovy.lang.MissingMethodException: No signature of method: static
Example.updateGlobalInteger() is applicable for argument types: (java.lang.Integer) values: [10]
Possible solutions: updateGlobalInteger(java.lang.Integer)
groovy.lang.MissingMethodException: No signature of method: static Example.updateGlobalInteger() is
applicable for argument types: (java.lang.Integer) values: [10]
Possible solutions: updateGlobalInteger(java.lang.Integer)
at Example.main(main.groovy:14)


错误消息说您不能直接访问静态区域中的非静态方法,这在java中是明确指定的

捕获:groovy.lang.MissingMethodException:没有方法的签名:static Example.updateGlobalInteger

类方法不能直接访问实例变量或实例方法,它们必须使用对象引用。此外,类方法不能使用this关键字,因为没有可引用的实例

所以要么让这个方法静态

java.lang.NullPointerException: Cannot invoke method size() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
或者使用对象引用

static Integer updateGlobalInteger(Integer errorC) {
    errorCount=errorC
   return errorCount
}

如果不创建对象,就不能使用非静态方法。contain为null,因为找不到字符串错误。另外,如果您只需要包含所有日志项的字符串,请使用.join,-错误是构建非常复杂Hanks:我刚刚尝试了您的方法,没有以前的错误。但在iIntelliJ条件下运行时出现以下错误:UpdateGlobalIntegrateErrorrc | | 0对此错误有何建议?谢谢:如果它返回null,也许我可以试试,然后将它设置为int 0
java.lang.NullPointerException: Cannot invoke method size() on null object
at org.codehaus.groovy.runtime.NullObject.invokeMethod(NullObject.java:91)
static Integer updateGlobalInteger(Integer errorC) {
    errorCount=errorC
   return errorCount
}
static void main(String[] args) { 
 // Example of an Integer using def 
 def rint = 1..10
 Integer errorC = rint.size().toInteger()
 println(errorC) //print result is 10
 Example e = new Example()
 e.updateGlobalInteger(errorC)
}