未捕获的TypeError:对象#<object>在文件中没有方法'exec':///android_asset/www/js/webSocket.js:51 </object>

时间:2013-07-24 00:49:54

标签: android cordova

我在这里使用这个websocket编程。https://github.com/knowledgecode/WebSocket-for-Android.But按照步骤后我得到了这个错误。我正在使用cordova 2.7。你能告诉我如何编写这个问题

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

这是我的html文件..

<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>

1 个答案:

答案 0 :(得分:0)

一种可能性是你的一个库(cordova.js,webSocket.js)正在扩展Object.prototype,而另一个是使用Objects作为哈希表而不检查hasOwnProperty()。如果是这种情况,您需要找到其中一个库的替代品或自己动手。请参阅此related question