Cordova相机应用程序非法参数例外

时间:2018-03-21 02:44:26

标签: cordova

如何确定确切的错误消息而不是Illegal argument Exception?我正在使用visual studio和avd manager来启动android模拟器。以下是代码,但是当我单击click按钮时,错误消息只是ILLEGAL ARGUMENT EXCEPTION

的index.html

<html>
    <head>
        <!--
        Customize this policy to fit your own app's needs. For more guidance, see:
            https://github.com/apache/cordova-plugin-whitelist/blob/master/README.md#content-security-policy
        Some notes:
            * gap: is required only on iOS (when using UIWebView) and is needed for JS->native communication
            * https://ssl.gstatic.com is required only on Android and is needed for TalkBack to function properly
            * Disables use of inline scripts in order to mitigate risk of XSS vulnerabilities. To change this:
                * Enable inline JS: add 'unsafe-inline' to default-src
        -->
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <p id="msg">TESTING</p>
        <button id="btn1">Click</button>

        <img src="" id="img1" />

        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

index.js

/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function() {
        document.getElementById('btn1').addEventListener('click', app.takephoto);
    },

    // Update DOM on a Received Event
    takephoto: function () {
        var ops = {
            quality: 50,
            destinationType: Camera.DestinationType.FILE_URL,
            //sourceType: Camera.PictureSourceType.CAMERA,
            //mediaType: Camera.MediaType.PICTURE,
            //encodingType: Camera.EncodingType.JPEG,
            //targetWidth: 300,
            //targetHeight: 400
        };
        navigator.camera.getPicture(app.ftw, app.wtf, ops);
    },
    ftw: function (imgURI) {
        document.getElementById('msg').textContent = imgURI;
        document.getElementById('img1').src = imgURI;
    },
    wtf: function (msg) {
        document.getElementById('msg').textContent = msg;
    }
};

app.initialize();

index.js更新了同样的错误

var app = {
    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    //
    // Bind any cordova events here. Common events are:
    // 'pause', 'resume', etc.
    onDeviceReady: function () {
        document.getElementById('msg').textContent = navigator.camera;
        document.getElementById('btn1').addEventListener('click', app.takephoto);
    },

    // Update DOM on a Received Event
    takephoto: function () {
        navigator.camera.getPicture(app.onSuccess, app.onFail, {
            quality: 50,
            destinationType: Camera.DestinationType.FILE_URI
        });
    },

    onSuccess: function (imageURI) {
        var image = document.getElementById('myImage');
        image.src = imageURI;
    },

    onFail: function (message) {
        alert('Failed because: ' + message);
    }


};

app.initialize();

enter image description here

2 个答案:

答案 0 :(得分:0)

我想这个问题是因为选项传递的语法不正确:

<br>
var ops = {
            quality: 50,<br>
            destinationType: Camera.DestinationType.FILE_URL **(removed comma from here)**<br>
            //sourceType: Camera.PictureSourceType.CAMERA,<br>
            //mediaType: Camera.MediaType.PICTURE,<br>
            //encodingType: Camera.EncodingType.JPEG,<br>
            //targetWidth: 300,<br>
            //targetHeight: 400<br>
        }<br>

请检查您现在是否面临同样的行为。

答案 1 :(得分:0)

new SqlFieldsQuery("select count(*) from \"ENTITY_FACT_DEV\".EntityFactDev")