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


目录
相关文章
|
6月前
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
Exception in thread “main“ java.lang.NoClassDefFoundError: freemarker/template/Configuration
162 0
|
3月前
|
Java
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
Exception in thread "main" java.lang.UnsatisfiedLinkError: xxx()V
20 0
|
6月前
|
Java 应用服务中间件
SprinBoot项目启动报错Exception in thread “main“ java.lang.reflect.InvocationTargetException
SprinBoot项目启动报错Exception in thread “main“ java.lang.reflect.InvocationTargetException
595 0
日常报错 - NO constructor found in matching [java.lang.String]解决方法
日常报错 - NO constructor found in matching [java.lang.String]解决方法
478 0
|
6月前
|
JSON 关系型数据库 MySQL
报错:Exception in thread "main" java.lang.UnsupportedOperationException
【1月更文挑战第19天】【1月更文挑战第94篇】报错:Exception in thread "main" java.lang.UnsupportedOperationException
93 1
|
11月前
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
Junit报错java.lang.Exception: No tests found matching [{ExactMatcher:fDisplayName=test]的解决
77 0
|
Java 测试技术
java.lang.IllegalStateException Unable to find a @SpringBootConfiguration代码报错
java.lang.IllegalStateException Unable to find a @SpringBootConfiguration代码报错
|
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()
|
Java 测试技术 Android开发
谈一谈JUnit神奇的报错 java.lang.Exception:No tests found matching
最近在学习Spring+SpringMVC+MyBatis,一个人的挖掘过程确实有点艰难,尤其是有一些神奇的报错让你会很蛋疼。特别是接触一些框架还是最新版本的时候,会因为版本问题出现很多错误,欢迎大家一起学习交流 这篇就说一下困扰我昨晚2小时的一个报错,nitializationError(org.junit.runner.manipulation.Filter)或者No tests found matching异常,查阅了很多资料,总结一下这些情况和解决办法。
|
Java 开发工具 Maven
nested exception is java.lang.NoClassDefFoundError解决方式
nested exception is java.lang.NoClassDefFoundError解决方式
1651 0