Bonne journée pour tous les programmeurs. J'ai un problème NullPointerException lorsque j'appelle la méthode showAtLocation de PopupWindow. Comme dans beaucoup de forums a été écrit, cette exception se produit parce que le premier paramètre de la méthode showAtLocation est null. Donc, je vérifie cette façon:NullPointErexception lors de l'appel showAtLocation
showAtLocation (View parent, int gravity, int x, int y)
parent.equals(null) //- it returns false
LinearLayout lout = (LinearLayout) parent;
lout.getChildCount() //- it returns true count of child elements
((TextView) lout.getChildAt(1)).getText() //- it returns a text which i write in android:text field
J'ai un Gridview et son adaptateur est CustomAdapter (étend BaseAdapter). Dans cette classe (CustomAdapter) a OnClickListener dans getView méthode. Je veux définir popupwindow pour chaque élément de cette grille. Donc, en OnClickListener j'appelle une méthode showPopup:
private void showPopup(final Activity context, Point p) {
int popupWidth = 200;
int popupHeight = 150;
// Inflate the popup_layout.xml
LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//LayoutInflater layoutInflater = prnt.getLayoutInflater();
View parent = layoutInflater.inflate(R.layout.popup_layout, viewGroup);
final PopupWindow popup = new PopupWindow(context);
popup.setContentView(parent);
popup.setWidth(popupWidth);
popup.setHeight(popupHeight);
popup.setFocusable(true);
int OFFSET_X = 30;
int OFFSET_Y = 30;
popup.setBackgroundDrawable(new BitmapDrawable());
/*
LinearLayout lout = (LinearLayout) parent;
showMsg(parent.equals(null) + " : type " + lout.getChildCount() + " - " + ((TextView) lout.getChildAt(1)).getText());
*/
popup.showAtLocation(parent, 0, p.x + OFFSET_X, p.y + OFFSET_Y); //error occurs here
}
S'il vous plaît, j'ai besoin de votre aide
double possible de [Qu'est-ce qu'un exception de pointeur nul, et comment puis-je résoudre ce problème?] (http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it) – soorapadman