尝试以代号

时间:2015-12-10 07:43:48

标签: codenameone

我试图调用下面的sayHi()函数,该函数在NativeTestImpl.java中实现

这些是我的文件:

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不为null。只有obj.isSupported()函数调用返回false,因此它将进入else部分。

1 个答案:

答案 0 :(得分:3)

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