问题描述
我在 此 链接.但现在我收到了这个错误.如何解决这个错误?
推荐答案
替换:
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;
问题描述
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?
推荐答案
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;
相关问答
插件不能解决为类型的问题-Cordova-2.7.0
PhoneGap(Cordova)2.7.0 + MAPKIT插件 +入门
Cordova-2.7.0.jar在哪里?
cordova-2.7.0.jar在哪里?
cordova | 2.7.0.jar在哪里?
Cordova 2.7.0 Pushplugin" Cordova无法解决"," CTX无法解决"
Cordova 2.7.0 PushPlugin "cordova无法解决 "和 "ctx无法解决"
有PhoneGap 2.7.0的Facebook插件吗?
JSP不能被解析为一个类型
FragmentActivity不能被解析为一个类型