【错误记录】Groovy 运行报错 ( Exception in thread “main“ groovy.lang.MissingMethodException: No signature of )
生活随笔
收集整理的這篇文章主要介紹了
【错误记录】Groovy 运行报错 ( Exception in thread “main“ groovy.lang.MissingMethodException: No signature of )
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、報錯信息
在使用 Groovy 閉包時 , 會報如下錯誤 :
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: Test$_main_closure3.call() is applicable for argument types: (java.lang.String) values: [Hello] Possible solutions: doCall(), any(), any(), each(groovy.lang.Closure), any(groovy.lang.Closure), each(groovy.lang.Closure)at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:284)at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1015)at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:806)at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:45)at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)at Test.main(Test.groovy:50)Execution failed for task ':Test.main()'. > Process 'command 'D:/Program Files/Java/jdk1.8.0_221/bin/java.exe'' finished with non-zero exit value 1二、解決方案
上述類型的錯誤 , 是由于閉包中傳入參數錯誤導致的 ;
Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: Test$_main_closure3.call() is applicable for argument types: (java.lang.String) values: [Hello] Possible solutions: doCall(), any(), any(), each(groovy.lang.Closure), any(groovy.lang.Closure), each(groovy.lang.Closure)原代碼 : 其中閉包中有 " -> " 符號 , 表示閉包不希望接收任何參數 ;
def closure2 = { ->println "Hello"}closure2("Hello")修改后代碼 : 刪除閉包中的參數 , 即可正確執行該閉包 ;
def closure2 = { ->println "Hello"}closure2()總結
以上是生活随笔為你收集整理的【错误记录】Groovy 运行报错 ( Exception in thread “main“ groovy.lang.MissingMethodException: No signature of )的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Groovy】闭包 Closure (
- 下一篇: 【Groovy】闭包 Closure (