我正在尝试使用 BackgroundMode.disableWebViewOptimizations();
在我的ionic应用程序中,但当我在android studio中启动该应用程序时,我会遇到此错误
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.siloc.users, PID: 6275
java.lang.NullPointerException: Attempt to invoke interface method 'android.view.View org.apache.cordova.CordovaWebViewEngine.getView()' on a null object reference
at de.appplant.cordova.plugin.background.BackgroundModeExt$1.lambda$run$0$BackgroundModeExt$1(BackgroundModeExt.java:169)
at de.appplant.cordova.plugin.background.-$$Lambda$BackgroundModeExt$1$ENae6xHnDD7pQOdOSwld6cT0QNo.run(Unknown Source:2)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:230)
at android.app.ActivityThread.main(ActivityThread.java:7880)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:526)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1034)
E/NetdClient: querySockNetidForUid nid:0, uid:10357, command.cmdId:11, id:0
这是backgroundmodeext.java文件中的函数
private void disableWebViewOptimizations() {
Thread thread = new Thread(){
public void run() {
try {
Thread.sleep(1000);
getApp().runOnUiThread(() -> {
View view = webView.getEngine().getView();
try {
Class.forName("org.crosswalk.engine.XWalkCordovaView")
.getMethod("onShow")
.invoke(view);
} catch (Exception e){
view.dispatchWindowVisibilityChanged(View.VISIBLE);
}
});
} catch (InterruptedException e) {
// do nothing
}
}
};
thread.start();
}
我有办法解决这个问题吗?
暂无答案!
目前还没有任何答案,快来回答吧!