I am trying to add a macaddress plugin into my project. but what i got is
“Failed to run constructor: TypeError: Object # has no method ‘addPlugin’ at file:///android_asset/www/javascripts/cordova-2.0.0.js:297 ” from the logchat. Can anybody kowns how can I deal with it to make my plugin work.
I am using plugin from https://github.com/phonegap/phonegap-plugins/tree/master/Android/MacAddress.
In my application.js files, I wrote
function onLoad() {
console.log('Init reached');
document.addEventListener('deviceready', onDeviceReady, false);
}
function onDeviceReady() {
console.log('Starting up...');
// navigator.app.overrideBackbutton(true);
document.addEventListener("backbutton", onBackKeyDown, false);
}
function getMacAddress(){
/*get macaddress*/
var networkInterface = {};
// Get network interface
networkInterface = window.plugins.macaddress.getMacAddress();
console.log(networkInterface.mac);
$("#wifi_mac_address").text(networkInterface.mac);
}
In index.html file, I wrote
<!DOCTYPE html>
<html>
<head>
...
<script type="text/javascript" charset="utf-8" src="javascripts/cordova-2.0.0.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/application.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/jquery/jquery.mobile-1.1.1.js"></script>
<script type="text/javascript" charset="utf-8" src="javascripts/MacAddress.js"></script>
</head>
<body onload="onLoad()">
...
<li data-theme="c">
WiFi mac address:
<span id="wifi_mac_address">
123
</span>
</li>
...
</body>
</html>
I started phonegap and Jquery mobile for just 3 weeks.Please give me some advices to solve it if you know.
Thanks a lot in advance.
Your scripts are wrongly placed, when you trying run your mac adress function you haven’t loaded your MacAdress.js, to fix your problem you need to place your scripts like this: