为什么 Codename One 的 NativeLookup.create return 为空?
Why does Codename One's NativeLookup.create return null?
我目前正在尝试让代号一在 windows phone 上使用一些本机代码。我创建了一个 "native demo" 项目,我将 NativeCalls
class 更改为仅支持一种简单的方法:
package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
public String testString();
}
从这个开始,我使用了上下文菜单项 "Generate Native",并在调用 testString
时将 NativeCallsImpl.cs 文件更改为 return "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);
}
}
构建工作得非常好,它也可以在模拟器上运行。但是当我在 phone 上部署 xap 文件时(通过 WP Dev Tools,二维码不起作用,显示“无法安装公司应用程序”),应用程序正常启动但显示 NativeLookup
returned null。从 dist 目录中构建的 .jar 文件包含位于正确位置的 .cs 文件(com/codename1/nativedemo/NativeCallsImpl.cs,就在 NativeCalls.class 旁边)
如果在创建过程中抛出异常或出现故障,此查找将返回 null。
我不是 100% 确定它在当前 Windows Phone 端口中正常工作。
仅供参考当前 Windows Phone 端口已弃用并正在进行完全重写。
我目前正在尝试让代号一在 windows phone 上使用一些本机代码。我创建了一个 "native demo" 项目,我将 NativeCalls
class 更改为仅支持一种简单的方法:
package com.codename1.nativedemo;
import com.codename1.system.NativeInterface;
public interface NativeCalls extends NativeInterface {
public String testString();
}
从这个开始,我使用了上下文菜单项 "Generate Native",并在调用 testString
时将 NativeCallsImpl.cs 文件更改为 return "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);
}
}
构建工作得非常好,它也可以在模拟器上运行。但是当我在 phone 上部署 xap 文件时(通过 WP Dev Tools,二维码不起作用,显示“无法安装公司应用程序”),应用程序正常启动但显示 NativeLookup
returned null。从 dist 目录中构建的 .jar 文件包含位于正确位置的 .cs 文件(com/codename1/nativedemo/NativeCallsImpl.cs,就在 NativeCalls.class 旁边)
如果在创建过程中抛出异常或出现故障,此查找将返回 null。
我不是 100% 确定它在当前 Windows Phone 端口中正常工作。
仅供参考当前 Windows Phone 端口已弃用并正在进行完全重写。