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


目录
相关文章
|
5月前
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
111 0
|
2月前
|
Java
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
14 0
|
12月前
|
Java
解决java.lang.IllegalStateException: Failed to load ApplicationContext错误~
解决java.lang.IllegalStateException: Failed to load ApplicationContext错误~
121 0
|
5月前
|
Java 应用服务中间件
SprinBoot项目启动报错Exception in thread “main“ java.lang.reflect.InvocationTargetException
SprinBoot项目启动报错Exception in thread “main“ java.lang.reflect.InvocationTargetException
506 0
|
5月前
|
JSON 关系型数据库 MySQL
报错:Exception in thread "main" java.lang.UnsupportedOperationException
【1月更文挑战第19天】【1月更文挑战第94篇】报错:Exception in thread "main" java.lang.UnsupportedOperationException
83 1
日常报错 - NO constructor found in matching [java.lang.String]解决方法
日常报错 - NO constructor found in matching [java.lang.String]解决方法
414 0
|
10月前
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
67 0
Failed to start bean ‘documentationPluginsBootstrapper nested exception is java.lang.NullPointerE
Failed to start bean ‘documentationPluginsBootstrapper nested exception is java.lang.NullPointerE
55 0
|
Java 数据库 Spring
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
Failed to instantiate [java.lang.Long]: No default constructor found;nested exception is java.lang()
|
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
216 0
Exception in thread “main“ java.lang.RuntimeException: java.lang.RuntimeException: The root scratch