我目前正试图在windows phone上使用一些本机代码来获得代号。我创建了一个“原生示范”项目中,我改变了NativeCalls
类只支持一个简单的方法:为什么Codename One的NativeLookup.create返回null?
package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
public String testString();
}
从这一个我使用的上下文菜单项“生成本地”,改变了NativeCallsImpl.cs文件返回当调用testString
时,“windows phone”。我的最后一次更改是StateMachine
内:
protected void onGUI1_AddNativeButtonAction(Component c, ActionEvent event) {
super.onGUI1_AddNativeButtonAction(c, event);
try {
NativeCalls n = (NativeCalls) NativeLookup.create(NativeCalls.class);
if (n != null) {
if (n.isSupported()) {
Dialog.show("Got string", n.testString(), "OK", null);
} else {
Dialog.show("Error", "Platform not supported!", "OK", null);
}
} else {
Dialog.show("Error", "Native lookup returned null!", "OK", null);
}
c.getComponentForm().revalidate();
} catch (Throwable t) {
Dialog.show("Error", "Exception during native access: " + t, "OK", null);
}
}
构建运行完美,它也运行在模拟器上。但是当我在手机上部署xap文件时(通过WP开发工具,QR码不起作用,显示“公司应用程序无法安装)”,应用程序正常启动,但显示NativeLookup
返回null。 dist文件夹中的.jar文件包含位于正确位置的.cs文件(com/codename1/nativedemo/NativeCallsImpl.cs,除了NativeCalls.class之外)
在NativeCallsImpl.cs中,您是否将isSupported()方法设置为true?默认情况下,我认为这将是错误的。我想这可能不会帮助零问题,但这将是下一个问题。 –
是的,它返回true –