gpt4 book ai didi

android - 错误 : expected receiver of type com. MyApp.Main,但得到了 java.lang.Class

转载 作者:太空宇宙 更新时间:2023-11-03 12:36:26 25 4
gpt4 key购买 nike

我试图将一个类导入到 MVEL 的实现中,但出现以下错误:

[错误:预期接收者类型为 com.MyApp.Main,但得到的是 java.lang.Class]

这是设置 MVEL 的方法:

public void runCode() {
final String theCode = "Main.sendText();";
System.setProperty("java.version", "1.6");

new Thread(new Runnable() {

public void run() {

ParserContext context = new ParserContext();
context.addImport("Main", Main.class);
Serializable compiled = MVEL.compileExpression(theCode, context); // compile the expresion

HashMap vars = new HashMap();
vars.put("x", new Integer(10));
vars.put("y", new Integer(10));

Integer result = (Integer) MVEL.executeExpression(compiled, vars);
}
}).start();
}

主类:

public void sendText(){
System.out.println("Success!");
}

日志:

08-05 20:23:31.900: E/AndroidRuntime(19968): FATAL EXCEPTION: Thread-30751
08-05 20:23:31.900: E/AndroidRuntime(19968): [Error: expected receiver of type com.MyApp.Main, but got java.lang.Class<com.MyApp.Main>]
08-05 20:23:31.900: E/AndroidRuntime(19968): [Near : {... Main.sendText(); ....}]
08-05 20:23:31.900: E/AndroidRuntime(19968): ^
08-05 20:23:31.900: E/AndroidRuntime(19968): [Line: 1, Column: 1]
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:435)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:143)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.dynamic.DynamicOptimizer.optimizeAccessor(DynamicOptimizer.java:67)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.ast.ASTNode.optimize(ASTNode.java:159)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:115)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:113)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.MVEL.executeExpression(MVEL.java:969)
08-05 20:23:31.900: E/AndroidRuntime(19968): at com.MyApp.KessilLightScenes$1.run(KessilLightScenes.java:136)
08-05 20:23:31.900: E/AndroidRuntime(19968): at java.lang.Thread.run(Thread.java:856)
08-05 20:23:31.900: E/AndroidRuntime(19968): Caused by: java.lang.IllegalArgumentException: expected receiver of type com.MyApp.Main, but got java.lang.Class<com.MyApp.Main>
08-05 20:23:31.900: E/AndroidRuntime(19968): at java.lang.reflect.Method.invokeNative(Native Method)
08-05 20:23:31.900: E/AndroidRuntime(19968): at java.lang.reflect.Method.invoke(Method.java:511)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:1104)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:987)
08-05 20:23:31.900: E/AndroidRuntime(19968): at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:344)
08-05 20:23:31.900: E/AndroidRuntime(19968): ... 11 more

知道如何解决这个错误吗?谢谢

最佳答案

听起来您尝试访问的方法可能需要是静态的。

关于android - 错误 : expected receiver of type com. MyApp.Main,但得到了 java.lang.Class<com.MyApp.Main>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18071592/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com