Kotlin通用对话框不显示

无法显示通用对话框。我是Kotlin中的新手。有没有人遇到这个问题?

我努力了

class CommonStaticClass { fun showCommonPopUp(activity: Context, msg: String,drawable: Int): Dialog { val metrics = activity.resources.displayMetrics val dev_width = metrics.widthPixels val dev_height = metrics.heightPixels val dialogCommon = Dialog(activity) dialogCommon.window.setBackgroundDrawable(ColorDrawable(android.graphics.Color.TRANSPARENT)) dialogCommon.window.requestFeature(Window.FEATURE_NO_TITLE) dialogCommon.setContentView(R.layout.dialog_alert) dialogCommon.setCancelable(false) dialogCommon.setCanceledOnTouchOutside(false) dialogCommon.window.setLayout((dev_width* 85)/ 100, (dev_height* 25) / 100) val tv_headerObj = dialogCommon.findViewById(R.id.txt_header) as TextView val img_smileOBJ = dialogCommon.findViewById(R.id.img_smile) as ImageView img_smileOBJ.setImageResource(drawable) tv_headerObj.text = msg + "" dialogCommon.show() return dialogCommon } } 

Kotlin类

 val commonDIALOG= commonDialogOBJ!!.showCommonPopUp(getActivity()!!,"Your session has expired. Please log in",R.drawable.ic_sad) commonDIALOG.show() 

我已经宣布

  private var commonDialogOBJ : CommonStaticClass? = null commonDialogOBJ = CommonStaticClass() 

Kotlin language will be the best programming language for Android.