PopupWindow $BadTokenException: Unable to add window -- token null is not valid

I have the following error when showing a PopupWindow. The errors are triggered by the line: checkInPopup.showAtLocation((ViewGroup) mapView.getParent(), Gravity.CENTER_HORIZONTAL, 0, 0); mapView...