【错误记录】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


image.png




二、解决方案


上述类型的错误 , 是由于闭包中传入参数错误导致的 ;


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()


目录
相关文章
|
7月前
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
199 0
解决java.lang.IllegalStateException: Failed to load ApplicationContext错误~
解决java.lang.IllegalStateException: Failed to load ApplicationContext错误~
325 0
|
6月前
Exception in thread "main" java.lang.IllegalArgumentException: U+6570 ('.notdef') is not available in the font Helvetica-Bold, encoding: WinAnsiEncoding 这个问题如何解决
【6月更文挑战第19天】Exception in thread "main" java.lang.IllegalArgumentException: U+6570 ('.notdef') is not available in the font Helvetica-Bold, encoding: WinAnsiEncoding 这个问题如何解决
967 2
|
6月前
|
Java 数据库连接 数据库
Error:Internal error: (java.lang.NoClassDefFoundError) Could not initialize class com.intellij.util.
Error:Internal error: (java.lang.NoClassDefFoundError) Could not initialize class com.intellij.util.
|
7月前
Exception in thread “main“ java.lang.UnsupportedOperationException
Exception in thread “main“ java.lang.UnsupportedOperationException
36 1
|
7月前
|
JSON 关系型数据库 MySQL
报错:Exception in thread "main" java.lang.UnsupportedOperationException
【1月更文挑战第19天】【1月更文挑战第94篇】报错:Exception in thread "main" java.lang.UnsupportedOperationException
110 1
|
Java 测试技术
已解决 java.lang.Exception: No runnable methods 异常
已解决 java.lang.Exception: No runnable methods 异常
294 0
|
Java 数据库连接 Spring
java.lang.IllegalStateException: Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext
java.lang.IllegalStateException: Failed to load ApplicationContext解决方法
1.有没有小伙伴遇见过下面的异常,翻译过来就是不合法的状态异常:加载应用上下文失败
1315 0
java.lang.IllegalStateException: Failed to load ApplicationContext解决方法
|
SQL HIVE
Exception in thread “main“ java.lang.RuntimeException: java.lang.RuntimeException: The root scratch
Exception in thread “main“ java.lang.RuntimeException: java.lang.RuntimeException: The root scratch
223 0
Exception in thread “main“ java.lang.RuntimeException: java.lang.RuntimeException: The root scratch

热门文章

最新文章