我有一个正在运行的应用程序,当我点击表格的“编辑” 链接时,我在 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 均已正确实现,控件应继续到 edit jsp 页面。 我对日志中的错误表示怀疑的是,如果缺少关于反射 api 的任何 jar 文件。 请建议我解决这个问题的解决方案。任何有值(value)的建议都会有所帮助。非常感谢。
最佳答案
您正在使用方法 Field.getDeclaredAnnotation(Class)
。这个方法是在 Java 8 中引入的。它在 Java 7 及更早版本中不可用。您需要升级您的 JDK。
Field
是 AccessibleObject
的子类,并继承了该类的方法。参见 the Javadoc : 上面写着“Since: 1.8”,这是内部编号方案中 Java 8 的版本。
关于java - 调用 getDeclaredAnnotation() 时出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55990429/