我正在開發一個Phonegap插件。我的HTML文件看起來像這樣:未捕獲TypeError:無法調用未定義的方法'list'
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript">
function fun(){
alert("hai I am alert");
window.plugins.Unixell.list(SuccessCallBack ,failureCallBack);
function SuccessCallBack() {
alert("success");
};
function failureCallBack() {
alert("failure");
};
}
</script>
</head>
<body>
<input type="button" value="i am button" onclick="fun()" />
<script src='apis/Phonegap.js'></script>
<script src='apis/Unixell.js'></script>
</body>
</html>
和Unixell.js是:
var cam=function(){};
cam.prototype.list = function(successCallback, failureCallback) {
return PhoneGap.exec(successCallback,failureCallback, 'Unixell', 'list', [null]);
};
PhoneGap.addConstructor(function() {
alert("I am in unixell.js3333");
PhoneGap.addPlugin("Unixell", new cam());
PluginManager.addService("Unixell", "com.phonegap.plugins.unixell.Unixell");
});
而且我com.phonegap.plugins.unixell.Unixell.java文件是:
public class Unixell extends Plugin{
private static final String TAG = "unixell";
private static final String ACTION = "list";
@Override
public PluginResult execute(String action, JSONArray arg1, String arg2) {
// TODO Auto-generated method stub
PluginResult result = null;
result=new PluginResult(Status.OK, "I am a message");
if(ACTION.equals(action)){
System.out.println("success");
LOG.d(TAG,"U R success");
}
return result;
}
但我得到了一個logcat錯誤:
Uncaught TypeError: Cannot call method 'list' of undefined at file:///android_asset/www/index.html
什麼woul d是問題嗎?爲什麼我得到這個錯誤?這是什麼解決方案?
嗨,現在我改變了js文件,就像這樣.... var Unixell = function(){ }; Unixell.prototype.list = function(argument,successCallback,failureCallback){ // return PhoneGap.exec(successCallback,failureCallback,'BluetoothPlugin','listDevices',[argument]); \t console.log(「Entered function」); \t alert(「Entered function」); }; \t \t \t PhoneGap.addConstructor(函數(){ \t \t警報( 「我在unixell.js3333」); \t \t PhoneGap.addPlugin( 「Unixell」,新Unixell()); \t \t // \t \t PluginManager.addService(「Unixell」,「com.phonegap.plugins.unixell.Unixell」); \t}); – surya