我正在开发一个 Phonegap 插件。我的 HTML 文件如下所示:
<!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
会有什么问题?为什么我会收到此错误?解决方案是什么?