phonegap条形码扫描程序插件 - >参考错误

时间:2011-11-05 11:32:30

标签: javascript android cordova mobile

有人可以帮我这个:当我尝试运行项目时,这是我在index.html的头部的代码:

    <script type="text/javascript" src="barcodescanner.js"></script>
<script type="text/javascript" src="main.js"></script>

<script type="text/javascript" charset="utf-8" src="phonegap.js"></script>
<script type="text/javascript">
    function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}


// PhoneGap is loaded and it is now safe to make calls PhoneGap methods
//
function onDeviceReady() {
    window.plugins.barcodeScanner.scan( function(result) {
    alert("We got a barcode\n" +
              "Result: " + result.text + "\n" +
              "Format: " + result.format + "\n" +
              "Cancelled: " + result.cancelled);
}, function(error) {
    alert("Scanning failed: " + error);
}
);
}
</script>

我收到以下错误:

11-05 12:22:23.641: E/Web Console(454): ReferenceError: Can't find variable: PhoneGap at file:///android_asset/www/barcodescanner.js:57

该文件来自条形码扫描程序插件。它在正确的文件夹(project / assets / www)中。有人会对此有所帮助,会很棒。 感谢

编辑:

导致barcodescanner.js出现问题的行说明如下:

PhoneGap.addConstructor(function() {
PhoneGap.addPlugin('barcodeScanner', new BarcodeScanner());

});

1 个答案:

答案 0 :(得分:1)

我认为问题在于,您没有在maain HTML文件中为phonegap-XX.js指定正确的路径。