خرید بک لینک

Vote count: 0

I have a GridView. Each of the items in the GridView contain some ImageView and TextView. In the onLongPress() handler, I call the startDrag on the ImageView. Everything working ok without first item of gridView. I get the NullPointerExpception with it:

05-30 11:04:44.181 16591-16591/com.abc.xyz E/View: Unable to initiate drag
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View: java.lang.NullPointerException: Attempt to read from field 'android.view.IWindowSession android.view.View$AttachInfo.mSession' on a null object reference
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.view.View.startDrag(View.java:20983)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at com.abc.xyz.util.view.ESPeopleGridView$1.onItemLongClick(ES.java:55)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.widget.AbsListView.performLongPress(AbsListView.java:3939)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.widget.AbsListView$CheckForLongPress.run(AbsListView.java:3864)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.os.Handler.handleCallback(Handler.java:739)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.os.Handler.dispatchMessage(Handler.java:95)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.os.Looper.loop(Looper.java:158)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at android.app.ActivityThread.main(ActivityThread.java:7229)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at java.lang.reflect.Method.invoke(Native Method)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at com.android.inteal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
05-30 11:04:44.181 16591-16591/com.abc.xyz E/View:     at com.android.inteal.os.ZygoteInit.main(ZygoteInit.java:1120)

I was able to verify that all of the arguments passed to startDrag were non-null - a ClipData, a DragShadowBuilder, and my view as the LocalState. Here's that code snippet:

ClipData.Item item = new ClipData.Item(((ABC) getItemAtPosition(position)).getUri());
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData("", mimeTypes, item);
data.addItem(new ClipData.Item(position + ""));
DragShadowBuilder shadowBuilder = new DragShadowBuilder(view.findViewById(R.id.img_pp));
view.startDrag(data, // data to be dragged
        shadowBuilder, // drag shadow
        view, // local data about the drag and drop operation
        0 // no needed flags
);

I found that if set fixed size of GridView item in adapter, the issue will be occur. So, what I can do in this case and keep fixed size of GridView item.

v.setLayoutParams(new AbsListView.LayoutParams((int) mContext.getResources().getDimension(R.dimen.pp_item_w),
                (int) mContext.getResources().getDimension(R.dimen.pp_item_h)));

asked 1 min ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 10 خرداد 1395 ساعت: 12:08

صفحه بندی