android研究在android studio中的disablewebview()上出现错误

gdrx4gfi  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(839)

我正在尝试使用 BackgroundMode.disableWebViewOptimizations(); 在我的ionic应用程序中,但当我在android studio中启动该应用程序时,我会遇到此错误

  1. E/AndroidRuntime: FATAL EXCEPTION: main
  2. Process: com.siloc.users, PID: 6275
  3. java.lang.NullPointerException: Attempt to invoke interface method 'android.view.View org.apache.cordova.CordovaWebViewEngine.getView()' on a null object reference
  4. at de.appplant.cordova.plugin.background.BackgroundModeExt$1.lambda$run$0$BackgroundModeExt$1(BackgroundModeExt.java:169)
  5. at de.appplant.cordova.plugin.background.-$$Lambda$BackgroundModeExt$1$ENae6xHnDD7pQOdOSwld6cT0QNo.run(Unknown Source:2)
  6. at android.os.Handler.handleCallback(Handler.java:883)
  7. at android.os.Handler.dispatchMessage(Handler.java:100)
  8. at android.os.Looper.loop(Looper.java:230)
  9. at android.app.ActivityThread.main(ActivityThread.java:7880)
  10. at java.lang.reflect.Method.invoke(Native Method)
  11. at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
  12. at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
  13. E/NetdClient: querySockNetidForUid nid:0, uid:10357, command.cmdId:11, id:0

这是backgroundmodeext.java文件中的函数

  1. private void disableWebViewOptimizations() {
  2. Thread thread = new Thread(){
  3. public void run() {
  4. try {
  5. Thread.sleep(1000);
  6. getApp().runOnUiThread(() -> {
  7. View view = webView.getEngine().getView();
  8. try {
  9. Class.forName("org.crosswalk.engine.XWalkCordovaView")
  10. .getMethod("onShow")
  11. .invoke(view);
  12. } catch (Exception e){
  13. view.dispatchWindowVisibilityChanged(View.VISIBLE);
  14. }
  15. });
  16. } catch (InterruptedException e) {
  17. // do nothing
  18. }
  19. }
  20. };
  21. thread.start();
  22. }

我有办法解决这个问题吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题