简体   繁体   English

未捕获的ReferenceError:在文件:///android_asset/www/index.html:27上未定义show_pic

[英]Uncaught ReferenceError: show_pic is not defined at file:///android_asset/www/index.html:27

I am receiving the following error from eclipse (09-13 15:53:10.266: E/Web Console(24208): Uncaught ReferenceError: show_pic is not defined at file:///android_asset/www/index.html:27) when I attempt to call this function stored in main.js: 我从Eclipse中收到以下错误(09-13 15:53:10.266:E / Web Console(24208):未捕获的ReferenceError:show_pic未在file:///android_asset/www/index.html:27定义)我尝试调用存储在main.js中的此函数:

function show_pic() {
navigator.camera.getPicture(dump_pic, captureError, {
    quality : 50
});
}

Here is the html 这是HTML

 <!DOCTYPE HTML>
<html>
  <head>
    <meta name="viewport" content="width=device-width" />
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.1.1/jquery.mobile-1.1.1.min.js"></script>
<script src="cordova-2.0.0.js"></script>
<script src="main.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.1/jquery.mobile-     1.1.1.min.css" />
  <body>
  <div data-role="page">
  <div data-role="content">
  <div style="text-align:center;margin:20px;">
        <img id="cameraPic" src="" style="width:120px;height:120px;"></img>
    </div>
  </div>
    <div data-role="footer" data-position="fixed">      
        <div data-role="navbar">
            <ul>
                <li><a href="#">One</a></li>
                <li><a href="#" onClick="show_pic()">Two</a></li>
                <li><a href="#">Three</a></li>
            </ul>
        </div><!-- /navbar -->
    </div><!-- /footer -->
  </body>
    </html>

I mofidied your code a bit. 我修改了您的代码。 If I understood well, you want to display a picture that you take or that is in a specified location, when clicking on your navbar button Two . 据我了解,单击navbar按钮Two时,您想显示您拍摄的照片或在指定位置的照片。

According to what you want to do (displaying a picture that you are taking, or displaying a picture that is located in your device, etc), I defined 3 different functions show_pic , you may try them and use the one that fits your needs (2 of them are already in comments). 根据您要执行的操作(显示正在拍摄的图片或显示设备中的图片等),我定义了3个不同的函数show_pic ,您可以尝试使用它们并使用满足您需要的功能(其中2个已经在评论中)。

Also, while taking into account the previous suggestion in my comment, I included your function show_pic() directly inside the HTML code (in script tags) instead of main.js : 另外,考虑到我的评论中的先前建议,我将您的函数show_pic()直接包含在HTML代码内(在script标记中),而不是main.js

So here's the modified HTML file: 因此,这是修改后的HTML文件:

<!DOCTYPE html>
<html>
    <head>

        <meta name="viewport" content="width=device-width" />
        <meta http-equiv="Content-type" content="text/html; charset=utf-8">

        <!--  BASIC INCLUDES (TO CHANGE ACCORDING TO YOU) -->    

        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile.structure-1.1.0.min.css" />
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css" />

        <script type="text/javascript" charset="utf-8" src="cordova-2.0.0.js"></script>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>      
        <script type="text/javascript" src="http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.js"></script>

        <!--  END - BASIC INCLUDES --> 

        <script type="text/javascript" charset="utf-8">

            var pictureSource;   // picture source
            var destinationType; // sets the format of returned value 

            // Wait for Cordova to connect with the device
            //
            document.addEventListener("deviceready",onDeviceReady,false);

            // Cordova is ready to be used!
            //
            function onDeviceReady() {
                pictureSource=navigator.camera.PictureSourceType;
                destinationType=navigator.camera.DestinationType;
            }

            // Called when a photo is successfully retrieved
            //
            function onPhotoDataSuccess(imageData) {
                // Uncomment to view the base64 encoded image data
                // console.log(imageData);

                // Get image handle
                //
                var smallImage = document.getElementById('smallImage');

                // Unhide image elements
                //
                smallImage.style.display = 'block';

                // Show the captured photo
                // The inline CSS rules are used to resize the image
                //
                smallImage.src = "data:image/jpeg;base64," + imageData;
            }

            // Called when a photo is successfully retrieved
            //
            function onPhotoURISuccess(imageURI) {
                // Uncomment to view the image file URI 
                // console.log(imageURI);

                // Get image handle
                //
                var largeImage = document.getElementById('largeImage');

                // Unhide image elements
                //
                largeImage.style.display = 'block';

                // Show the captured photo
                // The inline CSS rules are used to resize the image
                //
                largeImage.src = imageURI;
            }

// YOUR FUNCTIONS `show_pic()` --------------------------------------------------
            // YOUR FUNCTION `show_pic()`
            //
            function show_pic() {
                // Take picture using device camera and retrieve image as base64-encoded string
                navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
                                        destinationType: destinationType.DATA_URL });
            }

//            // YOUR FUNCTION `show_pic()`. Ex of use: onclick="show_pic(pictureSource.PHOTOLIBRARY);"
//            //
//            function show_pic() {
//                // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
//                navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
//                                            destinationType: destinationType.DATA_URL });
//            }
//            
//            // YOUR FUNCTION `show_pic()`
//            //
//            function show_pic(source) {
//                // Retrieve image file location from specified source
//                navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
//                                            destinationType: destinationType.FILE_URI,
//                                            sourceType: source });
//            }

// END - YOUR FUNCTION `show_pic()` ----------------------------------------------

            // Called if something bad happens.
            // 
            function onFail(message) {
                alert('Failed because: ' + message);
            }


            </script>

    </head>
    <body>
        <div data-role="page">
            <div data-role="content">
                <div style="text-align:center;margin:20px;">
                    <img id="cameraPic" src="" style="width:120px;height:120px;"></img>
                </div>
            </div>
            <div data-role="footer" data-position="fixed">      
                <div data-role="navbar">
                    <ul>
                        <li><a href="#">One</a></li>
                        <li><a href="#" onClick="show_pic()">Two</a></li>
                        <li><a href="#">Three</a></li>
                    </ul>
                </div><!-- /navbar -->
            </div><!-- /footer -->
        </div>
    </body><!-- <-- You forgot this missing DIV -->

</html>

PS: PS:

  • Since you're importing CSS / JS files from external web (http://code.jquery.com/), make sure that you've added the appropriate whitelist rule to your file res/xml/cordova.xml . 由于您是从外部网站(http://code.jquery.com/)导入CSS / JS文件,因此请确保已将适当的白名单规则添加到文件res/xml/cordova.xml I guess you may need to add something like <access origin="http://code.jquery.com/" /> . 我想您可能需要添加类似<access origin="http://code.jquery.com/" /> Check this link for more information: http://docs.phonegap.com/en/2.0.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide . 检查此链接以获取更多信息: http : //docs.phonegap.com/en/2.0.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

  • Also, since you're developing on Android, make sure that you modify your file app/res/xml/ by adding: <plugin name="Camera" value="org.apache.cordova.CameraLauncher" /> , and your manifest app/AndroidManifest by adding <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> . 另外,由于您是在Android上进行开发,因此请确保通过添加以下内容来修改文件app/res/xml/<plugin name="Camera" value="org.apache.cordova.CameraLauncher" />和清单通过添加<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />来添加app/AndroidManifest


Hope this helps. 希望这可以帮助。 If you have any questions, you can ask me. 如果您有任何疑问,可以问我。

Also, for more useful information, you may wanna check the online doc: http://docs.phonegap.com/en/2.0.0/cordova_camera_camera.md.html#camera.getPicture 另外,有关更多有用的信息,您可能想查看在线文档: http : //docs.phonegap.com/en/2.0.0/cordova_camera_camera.md.html#camera.getPicture

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的TypeError:对象#<Object>在file:///android_asset/www/index.html上没有方法'exec' - Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/index.html 在phonegap中的file://android_asset/www/index.html上未定义函数 - function is not defined at file://android_asset/www/index.html in phonegap Reactjs-router-dom和cordova始终直接指向file:///android_asset/www/index.html - Reactjs-router-dom and cordova always direct to file:///android_asset/www/index.html 应用程序错误是一个目录(file:///#android_asset/www/index.html) - Application Error Is a directory (file:///#android_asset/www/index.html) 与服务器的连接不成功。(file:///android_asset/www/index.html) - The connection to the server was unsuccessful.(file:///android_asset/www/index.html) Phonegap / Android错误:未捕获ReferenceError:未在file:///android_asset/www/js/login.js:17定义url - Phonegap/Android error: Uncaught ReferenceError: url is not defined at file:///android_asset/www/js/login.js:17 index.html:42 Uncaught ReferenceError: 函数未定义 - index.html:42 Uncaught ReferenceError: function is not defined index.html:1未捕获的ReferenceError:在HTMLDivElement.onclick中未定义VARIABLE - index.html:1 Uncaught ReferenceError: VARIABLE is not defined at HTMLDivElement.onclick 未捕获的TypeError:无法读取未定义的属性&#39;OneSignal&#39;,来源:file:/// android_asset / www / js / app - Uncaught TypeError: Cannot read property 'OneSignal' of undefined", source: file:///android_asset/www/js/app 未捕获的 ReferenceError: setStatusClosed 未在 HTMLAnchorElement.onclick (index.html:1) 中定义 - Uncaught ReferenceError: setStatusClosed is not defined at HTMLAnchorElement.onclick (index.html:1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM