插件不能被解析为一个类型的问题- cordova-2.7.0[英] Plugin cannot be resolved to a type issue- cordova-2.7.0

本文是小编为大家收集整理的关于插件不能被解析为一个类型的问题- cordova-2.7.0的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我在 链接.但现在我收到了这个错误.如何解决这个错误?

在此处输入图片描述

推荐答案

您需要更新插件架构 (见这里),类似这样:

替换:

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

与:

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

变化:

public class PingPlugin extends Plugin {

到:

public class PingPlugin extends CordovaPlugin {

变化:

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

到:

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

更改失败的结果例如:

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

类似于:

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

更改成功结果如:

return new PluginResult(PluginResult.Status.OK);

类似于:

callbackContext.success();
return true;

其他推荐答案

发现在 Cordova 3.0 中,你还必须从 import 语句中删除"api".

改变

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

为此:

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

本文地址:https://www.itbaoku.cn/post/102565.html

问题描述

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?

enter image description here

推荐答案

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;

其他推荐答案

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;