【问题标题】:Plugin cannot be resolved to a type issue- cordova-2.7.0插件无法解析为类型问题-cordova-2.7.0
【发布时间】:2013-07-26 09:17:36
【问题描述】:

我在this 链接中给出的PhoneGap 应用程序中添加了Cordova-2.7.0.jar file and js 文件。但现在我收到了这个错误。如何解决这个错误?

【问题讨论】:

    标签: android cordova cordova-2.0.0


    【解决方案1】:

    我发现在 Cordova 3.0 中,您还必须从导入语句中删除“api”。

    改变

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

    到这里:

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

    【讨论】:

    • 非常感谢!拯救了我的一天。
    【解决方案2】:

    您需要更新插件架构 (see here),如下所示:

    替换:

    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;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-13
      • 2015-10-22
      • 2022-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-28
      相关资源
      最近更新 更多