找不到类使用自定义cordova插件的异常 [英] Class Not Found Exception using custom cordova plugin

查看:1877
本文介绍了找不到类使用自定义cordova插件的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个使用自定义API通过USB访问打印机的打印应用程序,所以我需要一个自定义的Cordova插件。我开始开发它,这是一个非常好的挑战,但目前也很令人沮丧,因为我无法弄清楚为什么我的插件无法正确使用。
事情是:
1.-插件安装正确并让我构建应用程序
2.- Javascript代码正确运行
3.-我收到运行时错误不会使应用程序崩溃。好像跳过了Java代码。我注意到Android Monitor出现了错误。

I'm developing a printing app that uses a custom API to access the printer via USB, so I needed a custom Cordova plugin. I started developing it, it has been a very good challenge but also very frustrating at the moment because I can't figure out why my plugin can't be used correctly. The thing is: 1.- The plugin installs correctly and lets me build the application 2.- The Javascript code runs correctly 3.- I get a runtime error that doesn't crash the app. It seems like the Java code is skipped. And I noticed there was an error in the Android Monitor.

你可以在这里找到我的插件:
< a href =https://github.com/krlozadan/cordova-custom-printer-plugin =nofollow noreferrer> https://github.com/krlozadan/cordova-custom-printer-plugin

You can find my plugin here: https://github.com/krlozadan/cordova-custom-printer-plugin

W/System.err: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter
W/System.err:     at java.lang.Class.classForName(Native Method)
W/System.err:     at java.lang.Class.forName(Class.java:324)
W/System.err:     at java.lang.Class.forName(Class.java:285)
W/System.err:     at org.apache.cordova.PluginManager.instantiatePlugin(PluginManager.java:489)
W/System.err:     at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:169)
W/System.err:     at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
W/System.err:     at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
W/System.err:     at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err:     at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err:     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)
W/System.err: Caused by: java.lang.ClassNotFoundException: Didn't find class "com.duplou.cordova.plugin.customprinter.CustomPrinter" on path: DexPathList[[zip file "/data/app/1/lib/1/base.apk!/lib/x86, /vendor/lib, /system/lib]]
W/System.err:     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
W/System.err:  ... 13 more
W/System.err:  Suppressed: java.lang.ClassNotFoundException: com.duplou.cordova.plugin.customprinter.CustomPrinter
W/System.err:     at java.lang.Class.classForName(Native Method)
W/System.err:     at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
W/System.err:     at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
W/System.err:     at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
W/System.err:      ... 14 more
W/System.err:  Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack trace available
I/System.out: Error adding plugin com.duplou.cordova.plugin.customprinter.CustomPrinter.
W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'void org.apache.cordova.CordovaPlugin.privateInitialize(java.lang.String, org.apache.cordova.CordovaInterface, org.apache.cordova.CordovaWebView, org.apache.cordova.CordovaPreferences)' on a null object reference
W/System.err:     at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171)
W/System.err:     at org.apache.cordova.PluginManager.exec(PluginManager.java:122)
W/System.err:     at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:57)
W/System.err:     at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
W/System.err:     at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)
W/System.err:     at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:53)
W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:102)
W/System.err:     at android.os.Looper.loop(Looper.java:148)
W/System.err:     at android.os.HandlerThread.run(HandlerThread.java:61)
D/SystemWebChromeClient: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js: Line 11 : Se terminó la ejecución
I/chromium: [INFO:CONSOLE(11)] "Se terminó la ejecución", source: file:///android_asset/www/plugins/cordova-custom-printer-plugin/www/custom-printer.js (11)
D/CordovaWebViewImpl: onPageFinished(file:///android_asset/www/index.html)
W/PluginManager: THREAD WARNING: exec() call to Sim.getSimInfo blocked the main thread for 53ms. Plugin should use CordovaInterface.getThreadPool().
D/SystemWebChromeClient: file:///android_asset/www/build/main.js: Line 1436 : ERROR
I/chromium: [INFO:CONSOLE(1436)] "ERROR", source: file:///android_asset/www/build/main.js (1436)
W/BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 12139
D/EGL_emulation: eglMakeCurrent: 0xae414a40: ver 2 0 (tinfo 0xa14bfbe0)







Here's my ionic info output
global packages:
@ionic/cli-utils : 1.5.0
Cordova CLI      : 7.0.1
Ionic CLI        : 3.5.0
local packages:

@ionic/app-scripts              : 1.3.7
@ionic/cli-plugin-cordova       : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms               : android 6.2.3
Ionic Framework                 : ionic-angular 3.2.1
System:

Node       : v6.10.3
OS         : macOS Sierra
Xcode      : Xcode 8.3.2 Build version 8E2002
ios-deploy : not installed
ios-sim    : not installed
npm        : 3.10.10


推荐答案

我看到你指向config.xml中的jar文件。如果你真的想继续使用这个jar文件,请确保路径在android平台文件夹中正确映射,并且它与类路径匹配。

I see that you are pointing to a jar file in your config.xml. If you really want to keep using this jar file make sure that the path is correctly mapped in android platform folders and it matches the classpath.

如果你想做一个简单的测试时,你应该逐个声明你的android源文件。所以在节点配置文件之后你应该添加几个这样的节点:

If you want to do a simple test, you should declare your android source files one by one. So after the node config-file you should add several nodes like this one:

<source-file src="src/android/src/net/mydomain/myplugin/MyClass.java" target-dir="src/mydomain/myplugin" /> 

这篇关于找不到类使用自定义cordova插件的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆