【问题标题】:How to solve "Native methods are not allowed in loaded code" error如何解决“加载的代码中不允许使用本机方法”错误
【发布时间】:2012-04-21 08:16:43
【问题描述】:

我想让我的应用程序在 playbook 处于待机模式时运行声音,我把这个语句放在启动中

QNXSystem.system.inactivePowerMode = QNXSystemPowerMode.THROTTLED;

现在,当我在模拟器(不是桌面调试器)上调试应用程序时出现此错误

VerifyError: Error #1079: Native methods are not allowed in loaded code.

我在使用 AlertDialog 时也遇到了这个错误。

注意:我使用的是 Flash builder,并且我已将 qnx SWC 放在库路径中。 ....那么解决这些问题?

【问题讨论】:

    标签: actionscript-3 air blackberry-playbook playbook


    【解决方案1】:

    为了允许使用原生扩展编译的代码在模拟器上运行,我们必须将使用原生扩展的代码放在永远不会被执行的方法中(在模拟器上时)。

    仅仅将有问题的代码包装在 if/else 块中是不够的。 if/else 需要调用另一个方法,该方法要么具有本机版本,要么具有代码的模拟器版本。

    例如:

    private function showNativeOrFlexAlert(message:String):void
    {
        // we used the Capabilities class to determine this, might be a better way
        if (isMobile)
            showNativeAlert(message);
        else
            showFlexAlert(message);
    }
    
    // have to be careful here, this method signature CANNOT include
    // any classes from native extension -- no errors on device, but fails on simulator
    private function showNativeAlert(message:String):void
    {
        // use native API to show alert
    }
    private function showFlexAlert(message:String):void
    {
        // use the Flex Alert class
    }
    

    【讨论】:

      【解决方案2】:

      将 qnx-air.swc 链接设置为“外部”。

      【讨论】:

      • 天哪!谢谢!
      猜你喜欢
      • 2016-09-19
      • 2021-12-20
      • 2015-10-12
      • 1970-01-01
      • 2014-03-21
      • 2018-09-08
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      相关资源
      最近更新 更多