在Rhino android中调用我自己的方法的问题

时间:2016-06-03 14:23:03

标签: javascript java android rhino

我一直在使用Rhino编写Minecraft PE脚本,我已经存在来自Java和android的库,我自己也想过为什么不创建我自己的类和脚本,现在我创建了一个android类......

Android类

package com.latch.to.modpe;
public class MainActivity extends android.app.Activity 
{
    private android.widget.Toast t;
    public void printToast()
    {
        t = new android.widget.Toast(getApplicationContext());
        t.makeText(getApplicationContext(), "Hello Minecraft from my java file", android.widget.Toast.LENGTH_LONG);
    }
}

我的JS文件

var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
var myClassFromFile = com.latch.to.modpe
function newLevel()
{
    ctx.runOnUiThread(new java.lang.Runnable() {
        run: function()
        {
            try
            {
                myClassFromFile.printToast();
            }
            catch(error)
            {
                clientMessage(error);
            }
        }
    });
}

但是当我跑它时它给了我错误

Cannot call property printToast in object [JavaPackage com.latch.to.modpe]. It is not a function it is an object. 

0 个答案:

没有答案