java共同方法_java-现有公共方法的NoSuchMethodError

我在下面粘贴的代码中面临一个非常神秘的java.lang.NoSuchMethodError.通过反射调用的相同方法按预期方式工作:

Widget a = getTextBoxWidget();

com.google.gwt.user.client.ui.UIObject uio = a; // Widget extends UIObject

for (java.lang.reflect.Method method : uio.getClass().getMethods()) {

if (method.getName().equals("getElement")) {

System.err.println("Method " + method.getName() + ":" +

method.getDeclaringClass().getName());

System.err.println("Modifier " +

java.lang.reflect.Modifier.toString(method.getModifiers()));

System.err.println("Parameter count: " + method.getParameterCount());

System.err.println("Parameter types: " + Arrays.asList(method.getParameterTypes()));

System.err.println("Return type: " + method.getReturnType());

try {

Object result = method.invoke(uio, new Object[0]);

System.err.println("Invocation successful: " + result);

Object result2 = method.invoke(uio, new Object[0]);

System.err.println("Invocation successful2: " + result2);

} catch (Exception e) {

System.err.println("Failed to invoke getElement: " + e);

e.printStackTrace(System.err);

}

}

}

// until here everything is good and it seems that

// we can call getElement and get the result, but...

Object result3 = uio.getElement(); // line 470, here I get java.lang.NoSuchMethodError

输出:

Method getElement:com.google.gwt.user.client.ui.UIObject

Modifier public

Invocation successful:

Invocation successful2:

Parameter count: 0

Parameter types: []

Return type: class com.google.gwt.dom.client.Element

堆栈跟踪:

java.lang.NoSuchMethodError: com.google.gwt.user.client.ui.UIObject.getElement()Lcom/google/gwt/user/client/Element;

at com.pyx4j.widgets.client.ValueBoxBase.setAriaLabel(ValueBoxBase.java:470)

可能是什么原因造成的?

uio.getClass().getClassLoader()是sun.misc.Launcher $AppClassLoader,id = 151

method.getDeclaringClass().getClassLoader()相同,具有相同的ID.

使用-verbose:class运行会显示从预期加载位置加载的UIObject类. UIObject.class内部的主要版本为52,与运行时主要版本(1.8)匹配

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值