Android layout 对话“继续投掷”;无法添加窗口--标记null不适用于应用程序;

Android layout 对话“继续投掷”;无法添加窗口--标记null不适用于应用程序;,android-layout,android-webview,android-dialog,android-context,Android Layout,Android Webview,Android Dialog,Android Context,我正在尝试创建一个包含relativelayout和webview的对话框。所以我创建了这个ShowInterstitual方法来显示对话框。但每次都会抛出“无法添加窗口--令牌null不适用于应用程序”错误 public void showInterstitial() { this.isInterstitial = true; openInterstitial(super.getContext(), showCloseButtonTime, autoCl

我正在尝试创建一个包含relativelayout和webview的对话框。所以我创建了这个ShowInterstitual方法来显示对话框。但每次都会抛出“无法添加窗口--令牌null不适用于应用程序”错误

public void showInterstitial() {
    this.isInterstitial = true;
    openInterstitial(super.getContext(), showCloseButtonTime,
            autoCloseInterstitialTime, this);
}

private void openInterstitial(Context context, Integer showCloseButtonTime,
        Integer autoCloseInterstitialTime, InterstitialView adView) {

    if (showCloseButtonTime == null || showCloseButtonTime < 0)
        showCloseButtonTime = 0;
    if (autoCloseInterstitialTime == null || autoCloseInterstitialTime < 0)
        autoCloseInterstitialTime = 0;

    final Dialog dialog;

    dialog = new Dialog(context,
            android.R.style.Theme_NoTitleBar_Fullscreen);

    adView.dialog = dialog;

    if (adView.getParent() != null) {
        ((ViewGroup) adView.getParent()).removeAllViews();
    }

    final RelativeLayout mainLayout = new RelativeLayout(context);
    mainLayout.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    adView.setLayoutParams(new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    mainLayout.addView(adView);

    Button closeButton = new Button(context);
    closeButton.setText("Close");
    RelativeLayout.LayoutParams closeParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT,
            RelativeLayout.LayoutParams.WRAP_CONTENT);
    closeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
            RelativeLayout.TRUE);
    closeParams.addRule(RelativeLayout.CENTER_HORIZONTAL,
            RelativeLayout.TRUE);
    closeButton.setLayoutParams(closeParams);
    closeButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });

    dialog.setContentView(mainLayout);
    dialog.show();
}
public void showInterstitual(){
this.isInterstitial=true;
OpenInterstitual(super.getContext(),showCloseButtonTime,
自动关闭时间,这个);
}
私有void openinterstitual(上下文上下文,整数showCloseButtonTime,
整数自动关闭(间隔时间,间隔视图adView){
if(showCloseButtonTime==null | | showCloseButtonTime<0)
showCloseButtonTime=0;
如果(AutoCloseInterstitutionAltime==null | | AutoCloseInterstitutionAltime<0)
自动关闭时间=0;
最终对话;
dialog=新建对话框(上下文,
android.R.style.Theme(非标题栏(全屏));
adView.dialog=对话框;
if(adView.getParent()!=null){
((ViewGroup)adView.getParent()).removeAllViews();
}
最终RelativeLayout mainLayout=新RelativeLayout(上下文);
mainLayout.setLayoutParams(新的ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_父级,
ViewGroup.LayoutParams.MATCH_PARENT);
adView.setLayoutParams(新建ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_父级,
ViewGroup.LayoutParams.MATCH_PARENT);
mainLayout.addView(adView);
按钮关闭按钮=新按钮(上下文);
closeButton.setText(“关闭”);
RelativeLayout.LayoutParams closeParams=新的RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_内容,
RelativeLayout.LayoutParams.WRAP_内容);
closeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM,
相对性(正确);
closeParams.addRule(相对长度、中心和水平),
相对性(正确);
closeButton.setLayoutParams(closeParams);
closeButton.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
dialog.dismise();
}
});
对话框.setContentView(主布局);
dialog.show();
}