Crash on call to notifydatasetchanged
mahavir155 opened this issue · 2 comments
Hi,
I don't know why but whenever i try calling notifydatasetchanged() method, it causes the gridview to crash.. Following is crash report::
java.lang.NullPointerException
at org.askerov.dynamicgrid.AbstractDynamicGridAdapter.getItemId(AbstractDynamicGridAdapter.java:68)
at android.widget.AbsListView.obtainView(AbsListView.java:2752)
at android.widget.GridView.onMeasure(GridView.java:1065)
at android.view.View.measure(View.java:17478)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1410)
at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1052)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:590)
at android.view.View.measure(View.java:17478)
at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:719)
at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:455)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:412)
at android.view.View.measure(View.java:17478)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5363)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2548)
at android.view.View.measure(View.java:17478)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2285)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1396)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1595)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6630)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5479)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
But if instead of mGridAdapter.notifyDatasetChanged(), if i call mGridAdapter.set(ArrayList items), it work great.. But to my mind, notifyDatasetChanged() should also work.. It should not make the system to crash.. Correct?
I call notifydatasetChanged() whenever there is any change in any item.
Am i doing anything wrong or missing anything?
Thank you,
Mahavir
You should probably paste some code. I call that like a million times and it's fine here.
If you modify items returned by getItems() you will loose reference for stable ids in AbstractDynamicGridAdapter.mIdMap. If you do that, set the modified list by calling BaseDynamicGridAdapter.set(List). This way mIdMap will be regenerated. Or use "add" and "remove" methods of BaseDynamicGridAdapter to modify items.