Gideon
Gideon

Reputation: 1507

groovy.langMissingMethodException in calling groovy function

I have a Grails GSP page similar to this:

<!DOCTYPE html>
<html lang="en">
    <head>
        ...
        <script type="text/javascript">
            var currency = ${Currency.getList() as JSON};
        </script>
    </head>
    ...
</html>

And a groovy file similar to this:

package enums
import java.util.List;

public final class Currency {
    private static final List CURRENCIES =  ['PHP','USD','HKD'];
    static List getList(){
        return CURRENCIES
    }
}

Now it shows an error message:

groovy.lang.MissingMethodException

No signature of method: static java.util.Currency.getList() is applicable for argument types: () values: [] Possible solutions: getAt(java.lang.String), getClass(), split(groovy.lang.Closure), notify(), wait()

How can I resolve this? The groovy file is placed in project/src directory, and is not allowed to move (if that helps).

Upvotes: 0

Views: 1277

Answers (2)

dsharew
dsharew

Reputation: 10665

According to the error message you are using a different Currency class from java.util package.


So try using your own class which is enums.Currency.getList() rather than java.util.Currencty.getList().


update:

Also import JSON class. According to your comments it seems my answer is not clear for you. So your code will be like this:

package enums
import java.util.List;
import grails.converters.JSON;

public final class Currency {
    private static final List CURRENCIES =  ['PHP','USD','HKD'];
    static List getList(){
        return CURRENCIES
    }
}

Upvotes: 2

CasperB
CasperB

Reputation: 11

Since you call the static groovy function from inside your HTML, I suspect you need to add the modifier "public" to your static method so:

public static List getList()

EDIT: Above is not the issue, but the exception complains about the class Currency from the java.util package, not from your own package "enums".

Upvotes: 1

Related Questions