[英]cordova.exec error Class not found
I'm attempting to write a plugin for phonegap that will access native Java that I have written. 我试图编写一个用于phonegap的插件,该插件将访问我编写的本机Java。 The only problem is that when I call cordova.exec, the failure callback message is "Class not found".
唯一的问题是,当我调用cordova.exec时,失败回调消息是“找不到类”。 I'm assuming this means that it can't find the java file, but I don't know why.
我假设这意味着它找不到Java文件,但我不知道为什么。
Here is my code. 这是我的代码。 Javascript:
使用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;
Java: Java的:
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;
}
}
}
plugin.xml plugin.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>
In logcat, I get this error: 在logcat中,出现此错误:
D/PluginManager(12316): exec() call to unknown plugin: SerialHelper
Any help would be much appreciated. 任何帮助将非常感激。
Thanks. 谢谢。
Wow....so, I was putting the plugin in a custom package. 哇...。所以,我将插件放在自定义包中。 That was messing everything up!
那简直糟透了!
The simple change from: com.isabellaproducts.serialhelper to com.phonegap.plugins.serialhlper 简单的更改:从com.isabellaproducts.serialhelper到com.phonegap.plugins.serialhlper
It now looks like this. 现在看起来像这样。 Javascript:
使用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;
Java: Java的:
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;
}
}
}
plugin.xml: plugin.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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.