相关疑难解决方法(0)

错误:com.MyApp.Main类型的预期接收者,但得到了java.lang.Class <com.MyApp.Main>

我正在尝试将类导入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();
}
Run Code Online (Sandbox Code Playgroud)

Main.class:

public void sendText(){
System.out.println("Success!");
}
Run Code Online (Sandbox Code Playgroud)

logcat的:

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, …
Run Code Online (Sandbox Code Playgroud)

android mvel

3
推荐指数
1
解决办法
4581
查看次数

标签 统计

android ×1

mvel ×1