java - 调用 getDeclaredAnnotation() 时出现 NoSuchMethodError

标签 java nosuchmethoderror

我有一个正在运行的应用程序,当我点击表格的“编辑” 链接时,我在 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。

FieldAccessibleObject 的子类,并继承了该类的方法。参见 the Javadoc : 上面写着“Since: 1.8”,这是内部编号方案中 Java 8 的版本。

关于java - 调用 getDeclaredAnnotation() 时出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55990429/

相关文章:

java - 这个 "NoSuchMethod"异常中缺少哪个方法?

flutter | Dart - NoSuchMethodError : The method 'map' was called on null

java - HYBRIS - 组件和插槽如何在 JSP 文件中工作?

java - Java5 中的方法公司在另一个泛型中带有一个泛型

java - 如何找到2位数字的颠倒

java - 无法在 JAVA 中使用 GMAIL api 获取前 10 条消息?

java - 如何创建 vs-code 任务以在 tomcat 扩展上部署 WAR 文件?

flutter - 在空方法上调用了 '[]'方法。 flutter

java - 如果带有 getConstructor() 的内部类如何创建实例

带有@PreAuthorize 注解的java.lang.NoSuchMethodError