Plugin cannot be resolved to a type issue- cordova-2.7.0

萝らか妹 提交于 2019-12-03 22:35:54

问题


I have added Cordova-2.7.0.jar file and js file in the PhoneGap application given in this link. But now i'm getting this error. How to solve this error?


回答1:


You need to update the plugin architecture (see here), something like this:

Replace:

import org.apache.cordova.api.Plugin;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;

with:

import org.apache.cordova.api.CallbackContext;
import org.apache.cordova.api.CordovaPlugin;

Change:

public class PingPlugin extends Plugin {

to:

public class PingPlugin extends CordovaPlugin {

Change:

public PluginResult execute(String action, JSONArray args, String callbackId) {

to:

public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {

Change failed results such as:

return new PluginResult(PluginResult.Status.ERROR, e.getMessage());

to something like:

LOG.e("PingPlugin", "Error : " + e.getMessage());
return false;

Change success results such as:

return new PluginResult(PluginResult.Status.OK);

to something like:

callbackContext.success();
return true;



回答2:


I found that in Cordova 3.0 you have to also remove "api" from the import statement.

Change

import org.apache.cordova.api.CordovaPlugin;
import org.apache.cordova.api.PluginResult;

To this:

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.PluginResult;


来源:https://stackoverflow.com/questions/17877475/plugin-cannot-be-resolved-to-a-type-issue-cordova-2-7-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!