我收到以下錯誤,沒有簽名 - groovy.lang.MissingMethodException:法無簽名:Script64 $ _run_closure5_closure7_closure8_closure9_closure10_closure11.doCall()是適用於參數類型:(java.lang中。字符串)值:可能的解決方案:doCall(java.lang.Object中,java.lang.Object中),isCase(java.lang.Object中),在線路isCase(java.lang.Object中)錯誤:groovy.lang.MissingMethodException:方法
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
感謝您的快速回復蒂姆。但是,當我將一張地圖添加到列表中時,它生成爲 listgenerated = [[[name1:val1],[name2:val2]],[[name3:val3]]] ,我在那裏得到相同的錯誤。如果我的列表生成爲 - listgenerated = [[name1:val1],[name2:val2],[name3:val3]]它工作正常,但我的要求是 listgenerated = [[name1:val1,name2:val2], [name3:val3]]。如何通過將地圖添加到列表中來生成第一個列表。 – user2239090
@ user2239090你可以編輯你的問題,讓你的代碼實際上做你所說的嗎?我不能運行上面的東西丟失 –
您好添,我編輯我的問題添加缺少的代碼。謝謝你的幫助。 – user2239090