简体   繁体   English

如何修复 groovy.lang.MissingMethodException: No signature of method:

[英]how to fix groovy.lang.MissingMethodException: No signature of method:

I am trying to use this method without a closure我正在尝试在没有关闭的情况下使用此方法

def copyAndReplaceText(source, dest, targetText, replaceText){
    dest.write(source.text.replaceAll(targetText, replaceText))
}

def source = new File('C:/geretd/resumebak.txt') //Hello World
def dest = new File('C:/geretd/resume.txt') //blank

copyAndReplaceText(source, dest){
    it.replaceAll('Visa', 'Passport!!!!')
}

but when I run it I get the following error:但是当我运行它时,我收到以下错误:

groovy.lang.MissingMethodException: No signature of method: ConsoleScript3.copyAndReplaceText() is applicable for argument types: (java.io.File, java.io.File, ConsoleScript3$_run_closure1) values: [C:\geretd\resumebak.txt, C:\geretd\resume.txt, ...]
Possible solutions: copyAndReplaceText(java.lang.Object, java.lang.Object, java.lang.Object, java.lang.Object)

at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55)

at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:78)

at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:49)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)

at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:149)

What am I doing wrong?我究竟做错了什么?

Because you are passing three arguments to a four arguments method.因为您将三个参数传递给一个四参数方法。 Also, you are not using the passed closure.此外,您没有使用传递的闭包。

If you want to specify the operations to be made on top of the source contents, then use a closure.如果要指定要在source内容之上进行的操作,请使用闭包。 It would be something like this:它会是这样的:

def copyAndReplaceText(source, dest, closure){
    dest.write(closure( source.text ))
}

// And you can keep your usage as:
copyAndReplaceText(source, dest){
    it.replaceAll('Visa', 'Passport!!!!')
}

If you will always swap strings, pass both, as your method signature already states:如果您总是交换字符串,请传递两者,因为您的方法签名已经声明:

def copyAndReplaceText(source, dest, targetText, replaceText){
    dest.write(source.text.replaceAll(targetText, replaceText))
}

copyAndReplaceText(source, dest, 'Visa', 'Passport!!!!')

To help other bug-hunters.帮助其他漏洞猎人。 I had this error because the function didn't exist.我有这个错误,因为该函数不存在。

I had a spelling error.我有一个拼写错误。

In my case it was simply that I had a variable named the same as a function.就我而言,这只是我有一个与函数名称相同的变量。

Example:例子:

def cleanCache = functionReturningABoolean()

if( cleanCache ){
    echo "Clean cache option is true, do not uninstall previous features / urls"
    uninstallCmd = ""
    
    // and we call the cleanCache method
    cleanCache(userId, serverName)
}
...

and later in my code I have the function:后来在我的代码中我有这个功能:

def cleanCache(user, server){

 //some operations to the server

}

Apparently the Groovy language does not support this (but other languages like Java does).显然 Groovy 语言不支持这一点(但其他语言如 Java 支持)。 I just renamed my function to executeCleanCache and it works perfectly (or you can also rename your variable whatever option you prefer).我刚刚将我的函数重命名为executeCleanCache并且它运行良好(或者您也可以重命名您的变量,无论您喜欢什么选项)。

You can also get this error if the objects you're passing to the method are out of order.如果您传递给该方法的对象乱序,您也可能会收到此错误。 In other words say your method takes, in order, a string, an integer, and a date.换句话说,你的方法按顺序接受一个字符串、一个整数和一个日期。 If you pass a date, then a string, then an integer you will get the same error message.如果您传递日期,然后是字符串,然后是整数,您将收到相同的错误消息。

This may also be because you might have given classname with all letters in lowercase something which groovy (know of version 2.5.0) does not support.这也可能是因为您可能给 classname 中的所有字母都小写了一些 groovy(知道 2.5.0 版)不支持的东西。

class name - User is accepted but user is not.类名 - 接受用户,但不接受用户。

In my case problem is I commented firebase dependency in build.gradle file but still using this in debug build type:就我而言,问题是我在build.gradle文件中评论了build.gradle依赖,但仍在调试构建类型中使用它:

firebaseCrashlytics {
   mappingFileUploadEnabled true
}

Just make it commented to make it work.只需对其进行评论即可使其工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复groovy.lang.MissingMethodException:没有方法的签名 - how to fix groovy.lang.MissingMethodException: No signature of method Groovy:groovy.lang.MissingMethodException:方法未签名 - Groovy : groovy.lang.MissingMethodException: No signature of method jenkinspipeline groovy.lang.MissingMethodException:没有方法签名 - jenkinspipeline groovy.lang.MissingMethodException: No signature of method 捕获:groovy.lang.MissingMethodException:没有方法的签名 - Caught: groovy.lang.MissingMethodException: No signature of method groovy.lang.MissingMethodException:没有方法解析的签名 - groovy.lang.MissingMethodException: No signature of method resolution groovy.lang.MissingMethodException:没有方法的签名: - groovy.lang.MissingMethodException: No signature of method: groovy.lang.MissingMethodException:没有方法签名 - groovy.lang.MissingMethodException: No signature of method 错误:groovy.lang.MissingMethodException:没有方法签名 - ERROR:groovy.lang.MissingMethodException: No signature of method 如何解决问题groovy.lang.MissingMethodException:没有方法的签名: - how to resolve the issue groovy.lang.MissingMethodException: No signature of method: 如何修复“hudson.remoting.ProxyException:groovy.lang.MissingMethodException:没有方法签名:testFunc.call()” - How to fix 'hudson.remoting.ProxyException: groovy.lang.MissingMethodException: No signature of method: testFunc.call() '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM