groovy.lang.MissingMethodException:没有方法签名:com.x.License.add()适用于参数类型:(com.x.License)值

问题描述 投票:-1回答:1

我正在使用预定的工作来经常检索许可证。当我检索每个许可证的许可证时,我想将该许可证添加到每个帐户的哈希映射。在hashmap中,我有一个帐户和一个许可证列表。对于每个许可证,我尝试检查hashmap中是否已有许可证列表,如果没有我创建新列表并且工作正常。但是如果有一个列表,我会尝试将它添加到该列表中,并且由于某种原因它会抛出错误

licenses.each{license->
        List<License> licensesPerAccount =  accountLicenseMap.get(license.account)
        log.info("initial licenseperaccount " + licensesPerAccount)
        if(licensesPerAccount == null) {
            accountLicenseMap.put(license.account, license as List<License>)
        } else{
            log.info("licenseperaccount in else is " + licensesPerAccount)
            licensesPerAccount.push(license)
            log.info("licenseperaccount now is " + licensesPerAccount)
            accountLicenseMap.put(license.account, licensesPerAccount)
        }
    }

这是它抛出的错误:

错误2017-12-27 10:12:59,045 grails.plugins.quartz.listeners.ExceptionPrinterJobListener - 作业中发生异常:Grails Job org.quartz.JobExecutionException:groovy.lang.MissingMethodException:没有方法签名:com.x.License .add()适用于参数类型:(com.x.License)值:[com.x.License:10]可能的解决方案:any(),find(com.x.License),any(groovy.lang。闭包),wait(),last(),save()at grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:111)at org.quartz.core.JobRunShell.run(JobRunShell.java:202)在org.quartz.simpl.SimpleThreadPool $ WorkerThread.run(SimpleThreadPool.java:573)引起:groovy.lang.MissingMethodException:没有方法签名:com.x.License.add()适用于参数类型:(com .x.License)值:[com.x.License:10]可能的解决方案:any(),find(com.x.License),any(groovy.lang.Closure),wait(),last(),save ()at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:5 8)org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite $ PogoMetaMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:253)org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71)at org.codehaus位于com.x.NewLicenseJob的.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)$ _execute_closure1 $$ EQezpeTI.doCall(NewLicenseJob.groovy:32)at sun.reflect.GeneratedMethodAccessor629.invoke(Unknown Source)at at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:497)at org.springsource.loaded.ri.ReloadedTypeInvoker $ 2.invoke(ReloadedTypeInvoker.java:133 )org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1461)at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod。 java:325)at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMetho d(ClosureMetaClass.java:294)at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1021)at groovy.lang.Closure.call(Closure.java:426)at com.x.NewLicenseJob $ _execute_closure1.call(NewLicenseJob) .groovy)at groovy.lang.Closure.call(Closure.java:442)at com.x.NewLicenseJob $ _execute_closure1.call(NewLicenseJob.groovy)at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java: 2030)org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2015)atg.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:2056)at org.codehaus.groovy.runtime.dgm来自org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call的org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite $ PojoMetaMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:274)$ 162.invoke(未知来源)(PojoMetaMethodSite.java:56 )atg.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)at com.x.NewLicenseJob $$ EQezpeT2.exe在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)的sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)处可爱(NewLicenseJob.groovy:25)在java.lang.reflect.Method.invoke(Method.java:497)org.springsource.loaded.ri.ReloadedTypeInvoker $ 2.invoke(ReloadedTypeInvoker.java:133)at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke( ReflectiveInterceptor.java:1461)at grails.plugins.quartz.GrailsJobFactory $ GrailsJob.execute(GrailsJobFactory.java:104)...省略了2个常用帧

这就是它记录的内容:

INFO 2017-12-27 10:12:59,029 grails.app.jobs.com.x.NewLicenseJob - 初始licenseperaccount null Hibernate:选择account0_.id为id1_4_0_,account0_.approve_hours_by_manager为approve_2_4_0_,account0_.brand_id为brand_id3_4_0_,account0_.check_tags如check_ta4_4_0_,account0_.checkin_at_work_module如checkin_5_4_0_,account0_.cj1_export如cj6_4_0_,account0_.company_id如company_7_4_0_,account0_.csv_import如csv_impo8_4_0_,account0_.default_date_pattern如default_9_4_0_,account0_.default_date_time_pattern如default10_4_0_,account0_.default_time_pattern如default11_4_0_,account0_.default_time_zone如default12_4_0_ ,account0_.default_view如default13_4_0_,account0_.deleted如deleted14_4_0_,account0_.display_as_decimal如display15_4_0_,account0_.instant_feedback如instant16_4_0_,account0_.language如languag17_4_0_,account0_.match_registration_hours如match_r18_4_0_,account0_.payroll_hours如payroll19_4_0_,account0_.project_tags如project20_4_0_,account0 _.separate_date as separat21_4_0_,account0_.show_charts as show_ch22_4_0_,account0_.templa_link as templa_23_4_0_,account0_.vip_export as vip_exp24_4_0_ from account account0_ where account0_.id =? Hibernate:选择company0_.id为id1_14_0_,company0_.account_id为account_2_14_0_,company0_.address为address3_14_0_,company0_.city为city4_14_0_,company0_.cocnumber为cocnumbe5_14_0_,company0_.country为country6_14_0_,company0_.deleted为deleted7_14_0_,company0_.emailaddress为emailadd8_14_0_ ,company0_.logo_url as logo_url9_14_0_,company0_.name as name10_14_0_,company0_.phonenumber as phonenu11_14_0_,company0_.province as provinc12_14_0_,company0_.vatnumber as vatnumb13_14_0_,company0_.website as website14_14_0_,company0_.zipcode as zipcode15_14_0_ from company company0_ where company0_.id = ? INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount null INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - initial licenseperaccount [com.x.License:9] INFO 2017-12-27 10:12:59,045 grails.app.jobs.com.x.NewLicenseJob - licenseperaccount in else is [com.x.License:9]

grails groovy
1个回答
0
投票

我通过创建列表修复它,如下所示:

List<License> licenseList = []
            licenseList << license
            accountLicenseMap.put(license.account, licenseList)

而不是做accountLicenseMap.put(license.account, license as List<License>)

© www.soinside.com 2019 - 2024. All rights reserved.