找不到 cordova.exec 错误类
cordova.exec error Class not found
我正在尝试为phonegap编写一个插件,该插件将访问我编写的本机Java。 唯一的问题是,当我调用cordova.exec时,失败回调消息是"找不到类"。 我假设这意味着它找不到java文件,但我不知道为什么。
这是我的代码。Javascript:
var SerialHelper = {
getName: function(){
return "this is the name"
},
getSerial: function(success, failure) {
cordova.exec(
success, // success callback function
failure, // error callback function
'com.isabellaproducts.serialhelper.SerialHelper',
'getFableSerial',
[]
);
}
}
module.exports = SerialHelper;
爪哇岛:
package com.isabellaproducs.serialhelper;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova.*;
public class SerialHelper extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getFableSerial".equals(action)) {
String serial = "15345344132354";
callbackContext.success(serial);
//callbackContext.sendPluginResult(new PluginResult(Status.OK, serial));
return true;
}
else{
callbackContext.error("method not found");
return false;
}
}
}
插件.xml
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.isabellaproducts.serialhelper"
version="1.0">
<name>SerialHelper</name>
<description>Serial Helper gets the Fable gives serial number access</description>
<license>MIT</license>
<keywords>serial, helper, fable</keywords>
<js-module src="www/serial_helper.js" name="SerialHelper">
<clobbers target="com.isabellaproducts.serialhelper" />
</js-module>
<!-- android -->
<platform name="android">
<source-file src="src/android/com/isabellaproducts/serialhelper/SerialHelper.java" target-dir="src/com/isabellaproducts/serialhelper" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SerialHelper">
<param name="android-package" value="com.isabellaproducts.serialhelper.SerialHelper"/>
</feature>
</config-file>
</platform>
</plugin>
在日志猫中,我收到此错误:
D/PluginManager(12316): exec() call to unknown plugin: SerialHelper
任何帮助将不胜感激。
谢谢。
哇....所以,我把插件放在一个自定义包中。 这把一切都搞砸了!
从以下简单更改:com.isabellaproducts.serialhelper自com.phonegap.plugins.serialhlper
现在看起来像这样。Javascript:
var SerialHelper = {
getName: function(){
return "this is the name"
},
getSerial: function(success, failure) {
cordova.exec(
success, // success callback function
failure, // error callback function
'SerialHelper',
'getFableSerial',
[]
);
}
}
module.exports = SerialHelper;
爪哇岛:
package com.phonegap.plugins.serialhelper;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.apache.cordova.*;
public class SerialHelper extends CordovaPlugin
{
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getFableSerial".equals(action)) {
String serial = "15345344132354";
callbackContext.success(serial);
//callbackContext.sendPluginResult(new PluginResult(Status.OK, serial));
return true;
}
else{
callbackContext.error("method not found");
return false;
}
}
}
插件.xml:
<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
id="com.phonegap.plugins.serialhelper"
version="1.0">
<name>SerialHelper</name>
<description>Serial Helper gets the Fable gives serial number access</description>
<license>MIT</license>
<keywords>serial, helper, fable</keywords>
<js-module src="www/serial_helper.js" name="SerialHelper">
<clobbers target="com.phonegap.plugins.serialhelper" />
</js-module>
<!-- android -->
<platform name="android">
<source-file src="src/android/com/phonegap/plugins/serialhelper/SerialHelper.java" target-dir="src/com/phonegap/plugins/serialhelper" />
<config-file target="res/xml/config.xml" parent="/*">
<feature name="SerialHelper">
<param name="android-package" value="com.phonegap.plugins.serialhelper.SerialHelper"/>
</feature>
</config-file>
</platform>
</plugin>
相关文章:
- Node.js v6.2.0类扩展不是函数错误
- Jquery菜单操作不稳定,定位不正确,存在一般错误
- document.open/document.write没有正确地清除chrome中的文档——这是chrome的错误吗
- 试图在引导模式内动态生成图表,得到offsetWidth错误
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 我如何修复包含在captcha的addthis中的错误
- 同样,同样的错误'ahorcado.js:26未捕获类型错误:无法读取属性'beginPath'
- 节点是否需要模块传递带有方括号的arg?这是个错误吗
- Webpack/Rect:遵循egghead.io教程,但出现错误:您可能需要一个合适的加载程序来处理此文件类型
- CKFinder 3为所选文件返回错误的URL
- 同位素库错误:未捕获错误无布局模式包装生产线8
- 铬:“;未捕获的语法错误:意外的标记:"
- 如何通过自己获得Chrome扩展的用户反馈/错误报告
- 相位器状态未捕获参考错误
- /undefined在我的404错误日志中多次出现
- Javascript未捕获语法错误意外的标识符错误
- javascript:如何在antlr生成的Lexer中进行错误处理
- 未捕获的类型错误:对象没有方法“exec”
- Kohana - 使用“.exec”正则表达式发布javascript代码返回内部错误
- 找不到 cordova.exec 错误类