isSupported() 始终 returns false 尝试调用代号一中的本机函数时

isSupported() always returns false when trying to call a native function in codename one

我正在尝试调用下面在 NativeTestImpl.java

中实现的 sayHi() 函数

这些是我的文件:

NativeTest.java

package com.mycompany.myapp;

import com.codename1.system.NativeInterface;

public interface NativeTest extends NativeInterface {
    public String sayHi();  
}

NativeTestImpl.java

package com.mycompany.myapp;
public class NativeTestImpl implements com.mycompany.myapp.NativeTest {
    public String sayHi() {
        return "HI";
    }

    public boolean isSupported() {
        return true;
    }

}

MyApplication.java 的 start() 方法:

 public void start() {
        if(current != null){
            current.show();
            return;
        }
        String s=null;
        try
        {
            NativeTest obj = (NativeTest)NativeLookup.create(NativeTest.class);
            if(obj != null && obj.isSupported())
            {
                s=obj.sayHi();
            }
            else
            {
                 System.out.println("Native interface is not supported on this platform");
            }
        }
        catch(Throwable t) {
            Dialog.show("Error", "Exception during native access: " + t, "OK", null);
        }

        final Form f = new Form("Testing");
        f.setScrollable(false);
        TextField text=new TextField(s);
        f.addComponent(text);
        f.show();
    }

问题是当我 运行 在具有 nexus 皮肤的模拟器上时 obj.isSupported() 返回 false。我 运行 在调试模式下看到 obj 不为空。只有 obj.isSupported() 函数调用返回 false,因此它进入 else 部分。

我假设你还没有在 native/javase 目录下实现模拟器本机接口