[英]How to fix error in Dialog after dismiss and click again?
I'm developing webview app, the problem in OnJsAlert that when i click on the Dialog it opens after dismiss it and click again it stop my app, for sorry i can't get the problem from debugging . 我正在开发webview应用程序, OnJsAlert中的问题是,当我单击对话框时, 关闭它后将其打开,然后再次单击它会停止我的应用程序,对不起,我无法从调试中解决问题。
This is my MainActivity.class 这是我的MainActivity.class
@Override
public boolean onJsAlert(WebView view, String url, final String alertSource, final JsResult alertResult) {
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.setContentView(R.layout.activity_alert);
alertDialog.setCancelable(true);
TextView alertMessage = alertDialog.findViewById(R.id.alert_text);
alertMessage.setText(alertSource);
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
alertDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
alertResult.cancel();
}
});
alertDialog.show();
return true;
}
Edited : Log 编辑: 日志
W/InputEventReceiver: Attempted to finish an input event but the input event receiver has already been disposed.
W / InputEventReceiver:尝试完成输入事件,但输入事件接收器已被处置。 E/ViewRootImpl: sendUserActionEvent() mView == null W/System.err: android.util.AndroidRuntimeException: requestFeature() must be called before adding content W/System.err: at com.android.internal.policy.impl.PhoneWindow.requestFeature(PhoneWindow.java:331) at android.app.Dialog.requestWindowFeature(Dialog.java:1057) at com.xcoder.stepview.MainActivity$4.onJsAlert(MainActivity.java:285) at com.android.webview.chromium.WebViewContentsClientAdapter.handleJsAlert(WebViewContentsClientAdapter.java:606) at com.android.org.chromium.android_webview.AwContentsClientBridge.handleJsAlert(AwContentsClientBridge.java:73) at com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method) at com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5641) at java.lang.reflect.Method.invokeNat
E / ViewRootImpl:sendUserActionEvent()mView == null W / System.err:必须在添加内容W / System.err之前调用android.util.AndroidRuntimeException:requestFeature():在com.android.internal.policy.impl.PhoneWindow .requestFeature(PhoneWindow.java:331)位于android.app.Dialog.requestWindowFeature(Dialog.java:1057)位于com.xcoder.stepview.MainActivity $ 4.onJsAlert(MainActivity.java:285)位于com.android.webview.chromium com.android.org.chromium.android_webview.AwContentsClientBridge.handleJsAlert(AwContentsClientBridge.java:73)位于com.android.org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native)上的.WebViewContentsClientAdapter.handleJsAlert(WebViewContentsClientAdapter.java:606)在com.android.org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:27)在android.os.Handler.dispatchMessage(Handler.java:102)在android.os.Looper.loop(Looper.java:146) )在android.app.ActivityThread.main(ActivityThread.java:5641)在java.lang.reflect.Method.invokeNat ive(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1288) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104) at dalvik.system.NativeStart.main(Native Method) A/libc: Fatal signal 6 (SIGABRT) at 0x00002c6d (code=-6), thread 11373 (xcoder.stepview) Application terminated.
ive(本机方法),位于java.lang.reflect.Method.invoke(Method.java:515)W / System.err:位于com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1288) dalvik.system.NativeStart.main(本机方法)处的com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1104)A / libc:致命信号6(SIGABRT)在0x00002c6d(代码= -6),线程11373(xcoder.stepview)应用程序终止。
Your alertDialog
is created before public boolean onJsAlert(...)
method called and when it's called second time you got AndroidRuntimeException: requestFeature() must be called before adding content
because of you can't use requestWindowFeature()
with created dialog. 您的
alertDialog
是在调用public boolean onJsAlert(...)
方法之前创建的,并且在第二次调用时,您遇到了AndroidRuntimeException: requestFeature() must be called before adding content
由于无法在创建的对话框中使用requestWindowFeature()
,因此AndroidRuntimeException: requestFeature() must be called before adding content
。 You have to create new instance of dialog in this method or reuse global defined dialog. 您必须使用此方法创建对话框的新实例或重新使用全局定义的对话框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.