调用getDeclaredAnnotation()时发生java NoSuchMethodError
我有一个正在运行的应用程序,当我单击一个表的'Edit'链接时,我在NoSuchMethodError
的日志中得到一个错误,并且控件停留在当前页面,而不是继续到编辑页面
下面的代码在获取错误时被命中
Field[] fields = entityObj.getClass().getDeclaredFields();
for(int i=0;i<fields.length;i++){
Field field =fields[i];
field.setAccessible(true);
if(field.getDeclaredAnnotation(EmbeddedId.class)!=null){
return true;
}
}
return false;
在上面的代码行中,
if(field.getDeclaredAnnotation(EmbeddedId.class)!=null)
我得到了一个特别的错误
也提到日志如下
Caused by: java.lang.NoSuchMethodError: java.lang.reflect.Field.getDeclaredAnnotation(Ljava/lang/Class;)Ljava/lang/annotation/Annotation;
at com.sprint.neo.querymodel.common.QueryObjectUtil.checkEnitityIsHasEmbeddedId(QueryObjectUtil.java:131)
at com.sprint.neo.querymodel.common.EntityManager.getEntityObject(EntityManager.java:89)
at com.sprint.neo.querymodel.common.EntityManager.loadEntityObject(EntityManager.java:72)
at com.sprint.neo.querymodel.common.EntityManager.entityload(EntityManager.java:60)
at com.sprint.neo.querymodel.common.EntityManager.loadAndGetEntityObject(EntityManager.java:56)
at com.sprint.neo.querymodel.common.QueryObjectUtil.getListOfEntityObject(QueryObjectUtil.java:718)
at com.sprint.neo.querymodel.common.QueryObjectCache.excuteUpdate(QueryObjectCache.java:251)
at com.sprint.neo.querymodel.common.QueryObjectRow.excuteUpdate(QueryObjectRow.java:298)
at com.sprint.neo.engine.controller.actions.TaskViewEditAction.edit(TaskViewEditAction.java:83)
控件应转到编辑jsp页面,因为所有jsp都已正确实现。 对于日志中的错误,我怀疑的是,如果有任何关于反射api的jar文件丢失。 请给我一个解决这个问题的办法。任何有价值的建议都会有帮助。非常感谢
# 1 楼答案
您正在使用
Field.getDeclaredAnnotation(Class)
方法。这种方法是在Java8中引入的。它在Java7和更早版本中不可用。你需要升级你的JDKField
是AccessibleObject
的子类,并从该类继承方法。参见the Javadoc:上面写着“自:1.8”,这是内部编号方案中Java8的版本