您尝试过早显示popUpWindow,修复它,将Id作为主布局​​main_layout​​并使用下面的代码时会发生此错误

Java的:

findViewById(R.id.main_layout).post(new Runnable() {
public void run() {
popupWindow.showAtLocation(findViewById(R.id.main_layout), Gravity.CENTER, 0, 0);
}
});

科特林:

main_layout.post {
popupWindow?.showAtLocation(main_layout, Gravity.CENTER, 0, 0)
}

 解决方法就是postDelay 1000加个延时