NullPointerException:尝试调用虚拟方法'void org.apache.cordova.CordovaPlugin.privateInitialize

时间:2019-12-13 06:15:15

标签: java android cordova

我正在研究Cordova插件进行一些重构,并且在启动时开始遇到此崩溃:

__skills

我到处闲逛,发现了一些类似的问题:

但是解决方案对我不起作用...

1 个答案:

答案 0 :(得分:0)

我从其他问题中得到了一些线索,因为我在重构,所以我一直在使用--------- beginning of crash 12-12 21:42:29.791 4693 4693 E AndroidRuntime: FATAL EXCEPTION: main 12-12 21:42:29.791 4693 4693 E AndroidRuntime: Process: xyz.meris.app, PID: 4693 12-12 21:42:29.791 4693 4693 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{xyz.meris.app/xyz.meris.app.MainActivity}: 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 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3162) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3305) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1993) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.os.Looper.loop(Looper.java:216) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7266) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:494) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:975) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: Caused by: 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 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.PluginManager.getPlugin(PluginManager.java:171) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.PluginManager.startupPlugins(PluginManager.java:97) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.PluginManager.init(PluginManager.java:86) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.CordovaWebViewImpl.init(CordovaWebViewImpl.java:117) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.CordovaActivity.init(CordovaActivity.java:149) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at org.apache.cordova.CordovaActivity.loadUrl(CordovaActivity.java:224) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at xyz.meris.app.MainActivity.onCreate(MainActivity.java:39) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7353) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:7344) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1275) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3142) 12-12 21:42:29.791 4693 4693 E AndroidRuntime: ... 11 more 12-12 21:42:29.826 4693 4693 I Process : Sending signal. PID: 4693 SIG: 9 文件。

我注意到我与其他plugin.xml文件有此区别:

plugin.xml

因为我复制了 <feature name="CDVProcessLog"> <param name="android-package" value="xyz.meris.processlog.CDVProcessLog" /> <param name="onload" value="true" /> </feature> <feature name="ProcessLog"> <param name="android-package" value="xyz.meris.processlog.ProcessLog" /> + <param name="onload" value="true" /> </feature> 标记并填充了它,所以我复制了<feature>参数。一旦我删除了重复的onload参数,崩溃就会停止发生。

编辑: erp。原来我还有另一个导致此问题的错误。

删除延迟加载的onload参数onload。所以以后我会得到一个空指针错误。

我的真正问题是我的ProcessLog文件没有更新为我的.js类名。我已将其从CordovaPlugin更改为ProcessLogCDVProcessLog现在具有处理日志的细节,而ProcessLog主要具有cordova胶来在CDVProcessLog中调用我的方法。

我的ProcessLog文件需要更改:

.js