Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ArrayAdapter IndexOutOfBoundsException

Tags:

android

I'm trying to remove an item from listview by onclick action. But i'm getting arrayindexoutofbound exception. I deleted item from 11 size array, but it still trying to get 11. item.

        public void onClick(View v) {
            data.remove(getItemIndexByID(filteredData.get(position).getID()));
            filteredData.remove(position);      
            notifyDataSetChanged();

            flipMenu(lastHolder, 1);
            showPopup("Item Deleted"); 


        }

LOG:

    11-26 17:16:32.159: E/AndroidRuntime(26991): FATAL EXCEPTION: main
11-26 17:16:32.159: E/AndroidRuntime(26991): java.lang.IndexOutOfBoundsException: Invalid index 10, size is 10
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.util.ArrayList.get(ArrayList.java:304)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.innovationbox.passlocker.adapters.ListViewAdapter.getView(ListViewAdapter.java:100)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView.obtainView(AbsListView.java:2143)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.makeAndAddView(ListView.java:1831)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.fillDown(ListView.java:674)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.ListView.fillGap(ListView.java:638)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:4930)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4087)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer.doFrame(Choreographer.java:531)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Handler.handleCallback(Handler.java:725)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Handler.dispatchMessage(Handler.java:92)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.os.Looper.loop(Looper.java:137)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at android.app.ActivityThread.main(ActivityThread.java:5039)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.lang.reflect.Method.invokeNative(Native Method)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at java.lang.reflect.Method.invoke(Method.java:511)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
11-26 17:16:32.159: E/AndroidRuntime(26991):    at dalvik.system.NativeStart.main(Native Method)
like image 235
ChuKoNu Avatar asked Dec 05 '22 13:12

ChuKoNu


1 Answers

I noticed that ArrayAdapter's getcount method always returns same value, i overrided getCount() method like this, it works.

@Override
public int getCount() {
    return filteredData.size();
}
like image 63
ChuKoNu Avatar answered Jan 22 '23 02:01

ChuKoNu