Reputation: 6459
I have a ListView where I present some option, depending of a data get from database. When an item of that ListView is clicked, it should open an Activity. The listview is, normally, populated with two items. When I click on one of the items, everything goes ok. BUT, if I get out of the Activity, and click the other item, I get this exception:
08-10 13:00:35.724 22877-22877/? E/MessageQueue-JNI﹕ java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. Make sure your adapter calls notifyDataSetChanged() when its content changes. [in ListView(2131558531, class android.widget.ListView) with Adapter(class com.infaplic.lpi.Adapters.ListaTributosAdapter)]
at android.widget.ListView.layoutChildren(ListView.java:1555)
at android.widget.AbsListView.onTouchUp(AbsListView.java:3617)
at android.widget.AbsListView.onTouchEvent(AbsListView.java:3429)
at android.view.View.dispatchTouchEvent(View.java:7837)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1959)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:2072)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1519)
at android.app.Activity.dispatchTouchEvent(Activity.java:2467)
at com.infaplic.lpi.activities.SwipeActivity.dispatchTouchEvent(SwipeActivity.java:70)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:2020)
at android.view.View.dispatchPointerEvent(View.java:8017)
at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent(ViewRootImpl.java:3984)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3863)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3549)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3606)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3473)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3442)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3450)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3423)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5635)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5615)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5586)
at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:5715)
at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:185)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:138)
at android.os.Looper.loop(Looper.java:123)
It is pointing to this line:
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
onSwipeTouchListener.getGestureDetector().onTouchEvent(ev);
return super.dispatchTouchEvent(ev);//Get the exception here.
}
The ListView is populated this way:
adapter=new ListaTributosAdapter(c, SwipeActivity.beanElementosTributarios);
listView.setAdapter(adapter);
Where SwipeActivity.beanElementosTributarios is an static array list where the things I want to present in the list view are stored. At this point, there is only one place where the array is modified:
if(SwipeActivity.beanElementosTributarios==null){
SwipeActivity.beanElementosTributarios=new ArrayList<>();
}
SwipeActivity.beanElementosTributarios.add(bean);
you can change the arrayList in another point of the app, but that point of the app is not reached yet. When I debug, I see the arrayList has two items, as it should.
I am going crazy with this exception.
Anybody could help me? (If you need to see other parts of the code, please ask)
Thank you...
EDIT: If I click on the FIRST item of the list, it is presented ok. When I click on the SECOND element, the exception raises. But, if I click on the SECOND element of the list view first, it is presented normally, but if I click in the FIRST element after that, the Exception raises.
EDIT 2: It is not a duplicate of that question. There is no other threads apart of the UI thread, and the arrayList of the adapter is not changed at this point.
EDIT 3:
Found this: https://code.google.com/p/android/issues/detail?id=71936. Maybe a bug?
Upvotes: 1
Views: 120
Reputation: 46
You must call notifyDataSetChanged() on your adapter after change data in list. In error says that data in your adapter updated, but view show old data.
Upvotes: 1