我一直在致力于一个我在this question中描述的项目。我之前问过。我试图从一个名称是动态生成的类(并且该类在程序运行时编译)调用一个方法。我在方法 loadWatchFace("pebbleos.PebbleOS_"+ fileName); 调用
,然后在方法 Class watchFace = Class.forName("pebbleos.PebbleOS_"+ fileName);
,然后调用 currentWatchFace = watchFace.newInstance();
)runWatchFace()
中,我尝试使用以下方法调用该方法:
Method method = null;
try {
method = currentWatchFace.getClass().getMethod("initializeFace");
} catch (SecurityException | NoSuchMethodException e) {
System.out.println("Error");
}
method.invoke(currentWatchFace);
我的表盘代码取自文本文件,如下所示:
package pebbleos;
public class PebbleOS_Default {
public PebbleOS_Default () {
}
public void initializeFace() {
System.out.println(“Hello World”);
}
}
简单说明一下,上面的内容被认为是此错误的“原因”:java.lang.reflect.InitationTargetException
最佳答案
从您发布的代码来看,您似乎使用了错误的字符“
,它看起来很像”
,但它们并不相同。修复它,重新编译代码并重试。
关于java - 调用方法时出错 - java.lang.RuntimeException : Uncompilable source code - Erroneous tree type: <any>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30950219/