相关文章推荐
酒量小的企鹅  ·  Python ...·  1 年前    · 
阳刚的雪糕  ·  怎么让轮播图全屏-掘金·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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?

From a noob in groovy: I had the same exception, but for different reason. I defined a method later than I wanted to use in the beginning of the code. When I replaced it, it worked. – CsBalazsHungary Oct 20, 2014 at 12:03 Another caveat: If you are calling a static method of an outer class from an inner class without fully qualifying the outer method: static class Abc { private void test() { foo(); } } private static void foo() { } – Torsten Oct 12, 2018 at 8:46

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. 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!!!!')
                Thanks so much, this my first time with groovy, and I need help, quick question if I use the code below I will be passing 4 parameter right?   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, 'Visa', 'Passport!!!!')
– geretd
                Jul 1, 2013 at 18:58
                Yes. copyAndReplaceText() is the method name, and you are passing four arguments: 1st source, 2nd dest, 3rd 'Visa' and 4th 'Passport!!!!'
– Will
                Jul 1, 2013 at 19:11
                well honestly I never heard of groovy before until Friday, I have had to research on my own, now I am stuck at this requirement.   search and replace to temporary file named xxxx~, old text with new text  don't know how to do it
– geretd
                Jul 1, 2013 at 19:41
                But yeah I figured out groovy is very nice, it is not as rigid as java, even though it has it's base on it.
– geretd
                Jul 1, 2013 at 19:42
                @geretd Tim's approach to your earlier question in addition to the one you are using now will be useful once you are comfortable with the semantics and syntax of Groovy.
– dmahapatro
                Jul 1, 2013 at 20:04
                Thanks for pointing me in the right direction. My method names were not the same case. Oops!
– e.gad
                Jun 12, 2020 at 17:50

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). I just renamed my function to executeCleanCache and it works perfectly (or you can also rename your variable whatever option you prefer).

You can get this error any time your argument list is not correct for the method signature... – geneSummons Jan 31, 2020 at 19:34

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.

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:

firebaseCrashlytics {
   mappingFileUploadEnabled true

Just make it commented to make it work.

  • Remove/Delete node-module from root folder
  • npm uninstall cordova-android
  • npm install cordova-android@10.1.1
  • Now remove android platform using: ionic cordova rm platform android
  • Now add platform : ionic cordova platform add android
  • Build Android Project : ionic cordova build android
  • Problem will be resolved

    Thanks for contributing an answer to Stack Overflow!

    • Please be sure to answer the question. Provide details and share your research!

    But avoid

    • Asking for help, clarification, or responding to other answers.
    • Making statements based on opinion; back them up with references or personal experience.

    To learn more, see our tips on writing great answers.