Reputation: 7866
I am receiving a null pointer exception that I would like some assistance in understanding why. I am creating a custom pull-down drawer. I have a view, that appears over my Activity on button press (for now, until I implement the fling). This is how I am setting up my PopupWindow
popupMessage = new PopupWindow(view, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT, true);
popupMessage.setContentView(view);
// Clear the default translucent background
popupMessage.setBackgroundDrawable(null);
if(userType != null){
if (userType.contentEquals("kid")) {
popupMessage.setFocusable(false);
} else {
popupMessage.setFocusable(true);
}
}
popupMessage.setOutsideTouchable(true);
popupMessage.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
popupMessage.setAnimationStyle(R.style.PopupAnimation);
popupMessage.update();
// Icon is an imageVIew ** This is where the null pointer occurs **
popupMessage.showAsDropDown(icon, 0, -(35+8));
Why would this cause a null pointer exception? I have also tried
popupMessage.showAtLocation(icon, Gravity.TOP|Gravity.LEFT, 0, 0);
Here are my logs
Upvotes: 0
Views: 204
Reputation: 13936
popupMessage is obviously not null since you are able to do methods on the instance before the null pointer. Thus my guess is that icon is null, please confirm if this is the case.
popupMessage.setOutsideTouchable(true);
popupMessage.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
popupMessage.setAnimationStyle(R.style.PopupAnimation);
popupMessage.update();
// Icon is an imageVIew ** This is where the null pointer occurs **
popupMessage.showAsDropDown(icon, 0, -(35+8));
Upvotes: 1