簡體   English   中英

groovy.lang.MissingMethodException:沒有方法簽名

[英]groovy.lang.MissingMethodException: No signature of method

我收到以下錯誤 - groovy.lang.MissingMethodException: No signature of method: Script64$_run_closure5_closure7_closure8_closure9_closure10_closure11.doCall() 適用於參數類型:(java.lang.String) 值:可能的解決方案: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”單引號時在值周圍添加它,它將其作為字符,並且在打印兩個列表時似乎不同。 我無法弄清楚到底出了什么問題。 任何幫助表示贊賞。 謝謝。 Ref - Groovy:為具有屬性集合的對象集合動態創建 XML

我相信,你在哪里做:

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

你需要做:

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

並將地圖添加到列表而不是字符串。 很難說,因為你的代碼示例不會在沒有改動的情況下運行,我不知道是不是改動解決了問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM