简体   繁体   中英

Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/js/webSocket.js:51

I am using this websocket programming from here. https://github.com/knowledgecode/WebSocket-for-Android.But after following the steps i am getting this error.I am using cordova 2.7 .can you please tell me how to sove this prolem

Uncaught TypeError: Object #<Object> has no method 'exec' at file:///android_asset/www/js/webSocket.js:51

here is my html file..

<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p class="event received">Device is Ready</p>
            </div>
        </div>
        <script type="text/javascript" src="cordova.js"></script>
         <!--script type="text/javascript" src="js/webSocket.min.js"></script-->
           <script type="text/javascript" src="js/webSocket.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
        <script type="text/javascript">
        var ws = new plugins.WebSocket('ws://192.168.1.102/8101');

// onopen callback
ws.onopen = function () {
    console.log('onopen');
    this.send('hello');
};

// onmessage callback
ws.onmessage = function (data) {
    // The data is received text
    console.log(data);  // hello
    this.close();
};

// onerror callback
ws.onerror = function (message) {
    // The message is the reason of error
    console.log(message);
};

// onclose callback
ws.onclose = function (code) {
    // The code is the reason code of disconnection
    console.log(code);  // 1000
};
           // app.initialize();
        </script>
    </body>
</html>

One possibility is that one of your libraries (cordova.js, webSocket.js) is extending Object.prototype, and the other is using Objects as hash tables without checking hasOwnProperty(). If that's the case, you'll need to find a replacement for one of the libraries or roll your own. See this related question .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM