Uncaught TypeError: Failed to call method 'list' of undefined

advertisements

I am developing a Phonegap plugin. My HTML file looks like this:

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

and Unixell.js is:

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");
});

And my com.phonegap.plugins.unixell.Unixell.java file is:

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

But I got an error in logcat:

Uncaught TypeError: Cannot call method 'list' of undefined at file:///android_asset/www/index.html

What would be the problem? Why am I getting this error? What is the solution for this ?


I suppose that you can get a function by executing Unixell.prototype.list like you defined it, but I didn't work a lot with Phonegap ;- )