Home Ask Login Register

Developers Planet

Your answer is one click away!

serebrus February 2016

NullPointErexception when calling showAtLocation

Good day for all programmers. I have a problem NullPointerException when i call the method showAtLocation of PopupWindow. As in many forums was written, this exception happens because first parameter of method showAtLocation is null. So i check it this way:

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

I have a Gridview and its adapter is CustomAdapter (extends BaseAdapter). In this class (CustomAdapter) has OnClickListener in getView method. I want to set popupwindow for each item of this gridview. So in OnClickListener i call a method 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);

   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());


serebrus February 2016

02-10 13:49:34.148 2376-2376/com.iyb.wi.mobi I/art: Not late-enabling -Xcheck:jni (already on)
02-10 13:49:34.255 2376-2376/com.iyb.wi.mobi W/System: ClassLoader referenced unknown path: /data/app/com.iyb.wi.mobi-2/lib/x86
02-10 13:49:34.331 2376-2376/com.iyb.wi.mobi I/GMPM: App measurement is starting up, version: 8487
02-10 13:49:34.331 2376-2376/com.iyb.wi.mobi I/GMPM: To enable debug logging run: adb shell setprop log.tag.GMPM VERBOSE
02-10 13:49:34.501 2376-2392/com.iyb.wi.mobi D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
02-10 13:49:34.582 2376-2392/com.iyb.wi.mobi I/OpenGLRenderer: Initialized EGL, version 1.4
02-10 13:49:34.639 2376-2392/com.iyb.wi.mobi W/EGL_emulation: eglSurfaceAttrib not implemented
02-10 13:49:34.639 2376-2392/com.iyb.wi.mobi W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6dfbc0, error=EGL_SUCCESS
02-10 13:49:45.041 2376-2390/com.iyb.wi.mobi I/GMPM: Tag Manager is not found and thus will not be used
02-10 13:50:05.590 2376-2386/com.iyb.wi.mobi I/art: Background sticky concurrent mark sweep GC freed 11567(906KB) AllocSpace objects, 10(200KB) LOS     objects, 22% free, 2MB/3MB, paused 25.010ms total 151.250ms
02-10 13:50:05.670 2376-2392/com.iyb.wi.mobi W/EGL_emulation: eglSurfaceAttrib not implemented
02-10 13:50:05.670 2376-2392/com.iyb.wi.mobi W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xad6e5d00, error=EGL_SUCCESS
02-10 13:50:08.094 2376-2376/com.iyb.wi.mobi I/Choreographer: Skipped 141 frames!  The application may be doing too much work on its main thread.
02-10 13:50:08.165 2376-2392/com.iyb.wi.mobi E/Surface: getSlotFromBufferLocked: unknown buffer: 0xab793b90
02-10 13:50:34.728 2376-2392/com.iyb.wi.mobi W/EGL_emulation: eglSurfaceAttrib not implemented
02-10 13:50:34.728 2376-2392/com.iyb.wi.mobi W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xa1c51100, error=EGL_SUCCESS
02-10 13:50:35.582 2376-2392/com.iyb.wi.mobi E/Surface: getSlotFromBufferLocked: unknown b 

Post Status

Asked in February 2016
Viewed 2,286 times
Voted 4
Answered 1 times


Leave an answer

Quote of the day: live life

Devs Planet ®

2014-2016 www.devsplanet.com

Devs Planet © all rights reserved