Andrew
Andrew

Reputation: 98

No signature of method [] is applicable for argument types

Hi i have this service:

def insertAction(int Id, String Name){
        def sql = new Sql(dataSource)
        sql.execute("INSERT INTO  mn (id, name) VALUES ($Id,$Name)")
    }

this controller:

def save() {
       println params
       [contact: contactListService.insertAction(params.id,params.Name)]
        redirect action: "create"

And when i create a new entry i get this error

No signature of method: contactlist.ContactListService.insertAction() is applicable for argument types: (null, java.lang.String) values: [null, das] Possible solutions: insertAction(int, java.lang.String), listAction()

Upvotes: 1

Views: 19473

Answers (1)

Vampire
Vampire

Reputation: 38734

Well, like the error suggests.
You defined your first parameter to be int, but you give it null.
null can be taken for any object, but not for a primitive type like int. Either change your method parameter to be an object like Integer (or def to not specify an explicit type) and check for null inside your method, or check your params before you give its values to the method.

Upvotes: 1

Related Questions