![](/img/trans.png)
[英]spark java: java.lang.IllegalArgumentException: object is not an instance of declaring class
[英]method.invoke - java.lang.RuntimeException: java.lang.IllegalArgumentException: object is not an instance of declaring class
任何想法?
嘗試調用對象時出現錯誤。
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);
}
}
我認為這足夠了,但是仍然出錯,有人嗎?
它說的是entity
不是entityClazz
。 當然,當您通過反射setter.invoke
調用時,它會期望該類的一個對象。
嘗試輸出entity.getClass()
和entityClazz
,看看它們是否相同或至少entityClazz
是entity.getClass()
父entity.getClass()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.