简体   繁体   English

method.invoke-java.lang.RuntimeException:java.lang.IllegalArgumentException:对象不是声明类的实例

[英]method.invoke - java.lang.RuntimeException: java.lang.IllegalArgumentException: object is not an instance of declaring class

Any idea? 任何想法?

I got an error, when trying to invoke an object. 尝试调用对象时出现错误。

R java.lang.RuntimeException: java.lang.IllegalArgumentException: object is not an instance of declaring class

 Caused by: java.lang.IllegalArgumentException: object is not an instance of declaring class
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java(Compiled Code))
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code))
at java.lang.reflect.Method.invoke(Method.java(Compiled Code))
at com.test.corp.name.workflow.changetracking.changeimpl.FieldValueChange.apply(FieldValueChange.java:171)
 public void apply(DomainContext context) {
    try {
        final Class entityClazz = Class.forName(entityClass);
        Object entity = context.getEntity( entityClazz, primaryKey);
        Object entityChange = context.getChangeEntity(entityClazz, primaryKey);
        Method setter = getSetterMethod(entityClazz,fieldName);

        if(entity!=null)
            setter.invoke(entity, new Object[]{getValue()}); //this line 171
        if(entityChange!=null)
            setter.invoke(entityChange, new Object[]{getValue()});

    }catch(Exception e) {
        throw new RuntimeException(e);
    }
}

I think this is enough, but still errors, anyone? 我认为这足够了,但是仍然出错,有人吗?

What it says is that entity is not of the class entityClazz . 它说的是entity不是entityClazz When you call via reflection setter.invoke it expect an object of that class, of course. 当然,当您通过反射setter.invoke调用时,它会期望该类的一个对象。

Try to output entity.getClass() and entityClazz and see if they are the same or at least entityClazz is parent of entity.getClass() . 尝试输出entity.getClass()entityClazz ,看看它们是否相同或至少entityClazzentity.getClass()entity.getClass()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 spark java:java.lang.IllegalArgumentException:对象不是声明类的实例 - spark java: java.lang.IllegalArgumentException: object is not an instance of declaring class spring boot:java.lang.IllegalArgumentException:object不是声明类的实例 - spring boot : java.lang.IllegalArgumentException: object is not an instance of declaring class java.lang.IllegalArgumentException:对象不是声明类的实例 - java.lang.IllegalArgumentException: object is not an instance of declaring class Hibernate:java.lang.IllegalArgumentException:object不是声明类的实例 - Hibernate : java.lang.IllegalArgumentException: object is not an instance of declaring class java.lang.IllegalArgumentException:对象不是声明类的实例吗? - java.lang.IllegalArgumentException: object is not an instance of declaring class? exception java.lang.IllegalArgumentException:object不是在sun.reflect.NativeMethodAccessorImpl.invoke0声明类的实例 - exception java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0 Method.invoke抛出java.lang.IllegalArgumentException:参数数量错误 - Method.invoke throws java.lang.IllegalArgumentException: wrong number of arguments 在线程“主”中使用method.invoke异常java.lang.IllegalArgumentException:参数数量错误 - Using method.invoke Exception in thread “main” java.lang.IllegalArgumentException: wrong number of arguments Grails 3.2.4拒绝保存域实例:java.lang.IllegalArgumentException:object不是声明类的实例 - Grails 3.2.4 refuses to save domain instance: java.lang.IllegalArgumentException: object is not an instance of declaring class 无法反映。 异常java.lang.IllegalArgumentException:object不是声明类的实例 - Unable to reflect. Exception java.lang.IllegalArgumentException: object is not an instance of declaring class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM