groovy.lang.MissingMethodException:没有方法签名

时间:2013-04-03 07:10:47

标签: groovy

我收到以下错误 - groovy.lang.MissingMethodException:没有方法签名:Script64 $ _run_closure5_closure7_closure8_closure9_closure10_closure11.doCall()适用于参数类型:(java.lang.String)values:可能的解决方案:doCall(java.lang.Object,java.lang.Object) ,isCase(java.lang.Object),isCase(java.lang.Object)错误在行:

Code -  EDIT
import groovy.xml.*


List tempList = []
List listgenerated = []

def count = 0
for (a in 0..totalCount-1)
{ 

    //nameList and valueList lists will have all the contents added as below   commented pseudo code 
    /*for (b in 0..50) 
    { 
        nameList.add(b,number)     // number is some calculated value
        valueList.add(b,number)
        e.g. nameList=[name1, name2, name3,name4, name5]
             valueList =[val1, val2, val3, , val5]  

             listgenerated should be = [[name1:val1, name2:val2], [name3:val3, name4: , name5:val5]]                          
    } */


        tempList = []

        for (j in count..nameList.size())
        {
                count = j                             
                def nameKey =  nameList[j]
                def value
                if (nameKey != null)
                {
                    value =  valueList[j]
                    tempList << [(nameKey) : value]

                }                               
        }    
            count = count 
            listgenerated.putAt(a,tempList) 
            number = number +1
}   

def process = { binding, element, name ->
  if( element[ name ] instanceof Collection ) {
    element[ name ].each { n ->
      binding."$name"( n )
    }
  }
  else if( element[ name ] ) {
    binding."$name"( element[ name ] )
  }
}

class Form {
  List fields  
}



def list = [[ name:'a', val:'1' ], [ name:'b', val :'2', name2:4, xyz:'abc', pqr:'']]  //Edited list
f = new Form( fields: list )            //Works fine
f = new Form( fields: listgenerated )   //Gives the above error

String xml = XmlUtil.serialize( new StreamingMarkupBuilder().with { builder ->
  builder.bind { binding ->
    data {
      f.fields.each { fields ->
        item {
          fields.each { name, value ->
            process( binding, fields, name )
          }
        }
      }
    }
  }
} )

如果在创建“listgenerated”单引号的同时在值周围添加它,则将其作为字符并且在打印两个列表时看起来不同。 我无法弄清楚到底出了什么问题。任何帮助表示赞赏。谢谢。 参考 - Groovy: dynamically create XML for collection of objects with collections of properties

1 个答案:

答案 0 :(得分:0)

我相信,你在哪里:

//some loop to add multiple values to the list
listgenerated << name+":"+value   

你需要这样做:

//some loop to add multiple values to the list
listgenerated << [ (name): value ]

将地图添加到列表而不是字符串。很难说虽然你的代码示例不会在没有改动的情况下运行,但我不知道它是否是解决问题的改动