Android Adapter throw IndexOutOfBoundsException while scrollingIs there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Android java.lang.IndexOutOfBoundsException HeaderViewListAdapter.java lineList view showing error on scroll custom adapter
Are there any intersection of Theory A and Theory B?
Did any of the founding fathers anticipate Lysander Spooner's criticism of the constitution?
Why does resistance reduce when a conductive fabric is stretched?
Is a Lisp program in both prog-mode and lisp-mode?
Was adding milk to tea started to reduce employee tea break time?
How do Windows version numbers work?
'rm' (delete) thousands of files selectively
Credit union holding car note, refuses to provide details of how payments have been applied
Why does the autopilot disengage even when it does not receive pilot input?
How can I deal with a player trying to insert real-world mythology into my homebrew setting?
Why would guns not work in the dungeon?
Where is the USB2 OTG port on the RPi 4 Model B located?
Can I intentionally omit previous work experience or pretend it doesn't exist when applying for jobs?
<schwitz>, <zwinker> etc. Does German always use 2nd Person Singular Imperative verbs for emoticons? If so, why?
Does Google Maps take into account hills/inclines for route times?
Repeating redundant information after dialogues, to avoid or not?
Referring to different instances of the same character in time travel
Robbers: The Hidden OEIS Substring
What's the minimum number of sensors for a hobby GPS waypoint-following UAV?
Can I use "candidate" as a verb?
Why are Hobbits so fond of mushrooms?
Why do players in the past play much longer tournaments than today's top players?
Which states have a head of state or government from another country?
How do I determine whether a permit is required for a new gas line?
Android Adapter throw IndexOutOfBoundsException while scrolling
Is there a way to run Python on Android?How to save an Android Activity state using save instance state?Close/hide the Android Soft KeyboardWhy is the Android emulator so slow? How can we speed up the Android emulator?“Debug certificate expired” error in Eclipse Android pluginsIs there a unique Android device ID?What is 'Context' on Android?Proper use cases for Android UserManager.isUserAGoat()?Android java.lang.IndexOutOfBoundsException HeaderViewListAdapter.java lineList view showing error on scroll custom adapter
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
From firbase, I saw a lot of crash logs:
Fatal Exception: java.lang.IndexOutOfBoundsException
Invalid index 7, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:255)
java.util.ArrayList.get (ArrayList.java:308)
com.weex.app.adapters.CartoonReaderAdapter.getItemViewType (CartoonReaderAdapter.java:357)
android.widget.AbsListView$RecycleBin.getScrapView (AbsListView.java:7132)
android.widget.AbsListView.obtainView (AbsListView.java:2469)
android.widget.ListView.makeAndAddView (ListView.java:1920)
android.widget.ListView.fillUp (ListView.java:751)
android.widget.ListView.fillGap (ListView.java:690)
android.widget.AbsListView.trackMotionScroll (AbsListView.java:5579)
android.widget.AbsListView.scrollIfNeeded (AbsListView.java:3641)
android.widget.AbsListView.startScrollIfNeeded (AbsListView.java:3569)
android.widget.AbsListView.onInterceptTouchEvent (AbsListView.java:4711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2157)
it seems adapter.getItemViewType
throw IndexOutOfBoundsException
while flinging. I've checked my code, all notifyDataSetChanged
is called in main thread. Here is my adapter code:
@Override
public void notifyDataSetChanged()
Log.e("TAG","notify data change:"+Thread.currentThread().getName());
rebuildViewTypes();
super.notifyDataSetChanged();
@Override
public int getCount()
return viewTypes == null ? 0 : viewTypes.size();
private void rebuildViewTypes()
viewTypes.clear();
if (pictures == null
@Override
public Object getItem(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.item;
@Override
public long getItemId(int position)
return 0;
@Override
public int getViewTypeCount()
return 16;
/**
* @param position
* @return
*/
@Override
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
I'm confused. All the methods(dispatchTouchEvent
& notifyDataSetChanged
) should be called in main thread. So there's not thread safety problem. The viewTypes
data may be safe. The IndexOutOfBoundsException
is beyond my understanding.
Any idea please?
android listadapter
add a comment |
From firbase, I saw a lot of crash logs:
Fatal Exception: java.lang.IndexOutOfBoundsException
Invalid index 7, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:255)
java.util.ArrayList.get (ArrayList.java:308)
com.weex.app.adapters.CartoonReaderAdapter.getItemViewType (CartoonReaderAdapter.java:357)
android.widget.AbsListView$RecycleBin.getScrapView (AbsListView.java:7132)
android.widget.AbsListView.obtainView (AbsListView.java:2469)
android.widget.ListView.makeAndAddView (ListView.java:1920)
android.widget.ListView.fillUp (ListView.java:751)
android.widget.ListView.fillGap (ListView.java:690)
android.widget.AbsListView.trackMotionScroll (AbsListView.java:5579)
android.widget.AbsListView.scrollIfNeeded (AbsListView.java:3641)
android.widget.AbsListView.startScrollIfNeeded (AbsListView.java:3569)
android.widget.AbsListView.onInterceptTouchEvent (AbsListView.java:4711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2157)
it seems adapter.getItemViewType
throw IndexOutOfBoundsException
while flinging. I've checked my code, all notifyDataSetChanged
is called in main thread. Here is my adapter code:
@Override
public void notifyDataSetChanged()
Log.e("TAG","notify data change:"+Thread.currentThread().getName());
rebuildViewTypes();
super.notifyDataSetChanged();
@Override
public int getCount()
return viewTypes == null ? 0 : viewTypes.size();
private void rebuildViewTypes()
viewTypes.clear();
if (pictures == null
@Override
public Object getItem(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.item;
@Override
public long getItemId(int position)
return 0;
@Override
public int getViewTypeCount()
return 16;
/**
* @param position
* @return
*/
@Override
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
I'm confused. All the methods(dispatchTouchEvent
& notifyDataSetChanged
) should be called in main thread. So there's not thread safety problem. The viewTypes
data may be safe. The IndexOutOfBoundsException
is beyond my understanding.
Any idea please?
android listadapter
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55
add a comment |
From firbase, I saw a lot of crash logs:
Fatal Exception: java.lang.IndexOutOfBoundsException
Invalid index 7, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:255)
java.util.ArrayList.get (ArrayList.java:308)
com.weex.app.adapters.CartoonReaderAdapter.getItemViewType (CartoonReaderAdapter.java:357)
android.widget.AbsListView$RecycleBin.getScrapView (AbsListView.java:7132)
android.widget.AbsListView.obtainView (AbsListView.java:2469)
android.widget.ListView.makeAndAddView (ListView.java:1920)
android.widget.ListView.fillUp (ListView.java:751)
android.widget.ListView.fillGap (ListView.java:690)
android.widget.AbsListView.trackMotionScroll (AbsListView.java:5579)
android.widget.AbsListView.scrollIfNeeded (AbsListView.java:3641)
android.widget.AbsListView.startScrollIfNeeded (AbsListView.java:3569)
android.widget.AbsListView.onInterceptTouchEvent (AbsListView.java:4711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2157)
it seems adapter.getItemViewType
throw IndexOutOfBoundsException
while flinging. I've checked my code, all notifyDataSetChanged
is called in main thread. Here is my adapter code:
@Override
public void notifyDataSetChanged()
Log.e("TAG","notify data change:"+Thread.currentThread().getName());
rebuildViewTypes();
super.notifyDataSetChanged();
@Override
public int getCount()
return viewTypes == null ? 0 : viewTypes.size();
private void rebuildViewTypes()
viewTypes.clear();
if (pictures == null
@Override
public Object getItem(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.item;
@Override
public long getItemId(int position)
return 0;
@Override
public int getViewTypeCount()
return 16;
/**
* @param position
* @return
*/
@Override
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
I'm confused. All the methods(dispatchTouchEvent
& notifyDataSetChanged
) should be called in main thread. So there's not thread safety problem. The viewTypes
data may be safe. The IndexOutOfBoundsException
is beyond my understanding.
Any idea please?
android listadapter
From firbase, I saw a lot of crash logs:
Fatal Exception: java.lang.IndexOutOfBoundsException
Invalid index 7, size is 0
java.util.ArrayList.throwIndexOutOfBoundsException (ArrayList.java:255)
java.util.ArrayList.get (ArrayList.java:308)
com.weex.app.adapters.CartoonReaderAdapter.getItemViewType (CartoonReaderAdapter.java:357)
android.widget.AbsListView$RecycleBin.getScrapView (AbsListView.java:7132)
android.widget.AbsListView.obtainView (AbsListView.java:2469)
android.widget.ListView.makeAndAddView (ListView.java:1920)
android.widget.ListView.fillUp (ListView.java:751)
android.widget.ListView.fillGap (ListView.java:690)
android.widget.AbsListView.trackMotionScroll (AbsListView.java:5579)
android.widget.AbsListView.scrollIfNeeded (AbsListView.java:3641)
android.widget.AbsListView.startScrollIfNeeded (AbsListView.java:3569)
android.widget.AbsListView.onInterceptTouchEvent (AbsListView.java:4711)
android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2157)
it seems adapter.getItemViewType
throw IndexOutOfBoundsException
while flinging. I've checked my code, all notifyDataSetChanged
is called in main thread. Here is my adapter code:
@Override
public void notifyDataSetChanged()
Log.e("TAG","notify data change:"+Thread.currentThread().getName());
rebuildViewTypes();
super.notifyDataSetChanged();
@Override
public int getCount()
return viewTypes == null ? 0 : viewTypes.size();
private void rebuildViewTypes()
viewTypes.clear();
if (pictures == null
@Override
public Object getItem(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.item;
@Override
public long getItemId(int position)
return 0;
@Override
public int getViewTypeCount()
return 16;
/**
* @param position
* @return
*/
@Override
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
I'm confused. All the methods(dispatchTouchEvent
& notifyDataSetChanged
) should be called in main thread. So there's not thread safety problem. The viewTypes
data may be safe. The IndexOutOfBoundsException
is beyond my understanding.
Any idea please?
android listadapter
android listadapter
edited Mar 26 at 5:38
Kinjal
1481 silver badge8 bronze badges
1481 silver badge8 bronze badges
asked Mar 26 at 4:30
hzyhzy
84 bronze badges
84 bronze badges
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55
add a comment |
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55
add a comment |
2 Answers
2
active
oldest
votes
Index is starting with 0. In below code your position might be +1 higher than index of the array. So please check the position value.
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
Why? position should also start with 0.And the crash log doesn't match your comment:Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
add a comment |
try this might help -
@Override
public int getItemId(int position)
return position;
@Override
public int getViewTypeCount()
return viewTypes.size();
Do you mean:getViewTypeCount()
impactgetItemViewType()
?
– hzy
Mar 26 at 5:26
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349878%2fandroid-adapter-throw-indexoutofboundsexception-while-scrolling%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Index is starting with 0. In below code your position might be +1 higher than index of the array. So please check the position value.
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
Why? position should also start with 0.And the crash log doesn't match your comment:Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
add a comment |
Index is starting with 0. In below code your position might be +1 higher than index of the array. So please check the position value.
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
Why? position should also start with 0.And the crash log doesn't match your comment:Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
add a comment |
Index is starting with 0. In below code your position might be +1 higher than index of the array. So please check the position value.
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
Index is starting with 0. In below code your position might be +1 higher than index of the array. So please check the position value.
public int getItemViewType(int position)
CartoonReaderTypeItem item = viewTypes.get(position);
return item.type;
answered Mar 26 at 4:44
MagudeshMagudesh
1531 silver badge8 bronze badges
1531 silver badge8 bronze badges
Why? position should also start with 0.And the crash log doesn't match your comment:Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
add a comment |
Why? position should also start with 0.And the crash log doesn't match your comment:Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
Why? position should also start with 0.And the crash log doesn't match your comment:
Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
Why? position should also start with 0.And the crash log doesn't match your comment:
Fatal Exception: java.lang.IndexOutOfBoundsException Invalid index 7, size is 0
– hzy
Mar 26 at 5:22
add a comment |
try this might help -
@Override
public int getItemId(int position)
return position;
@Override
public int getViewTypeCount()
return viewTypes.size();
Do you mean:getViewTypeCount()
impactgetItemViewType()
?
– hzy
Mar 26 at 5:26
add a comment |
try this might help -
@Override
public int getItemId(int position)
return position;
@Override
public int getViewTypeCount()
return viewTypes.size();
Do you mean:getViewTypeCount()
impactgetItemViewType()
?
– hzy
Mar 26 at 5:26
add a comment |
try this might help -
@Override
public int getItemId(int position)
return position;
@Override
public int getViewTypeCount()
return viewTypes.size();
try this might help -
@Override
public int getItemId(int position)
return position;
@Override
public int getViewTypeCount()
return viewTypes.size();
answered Mar 26 at 5:03
Sujeet KumarSujeet Kumar
887 bronze badges
887 bronze badges
Do you mean:getViewTypeCount()
impactgetItemViewType()
?
– hzy
Mar 26 at 5:26
add a comment |
Do you mean:getViewTypeCount()
impactgetItemViewType()
?
– hzy
Mar 26 at 5:26
Do you mean:
getViewTypeCount()
impact getItemViewType()
?– hzy
Mar 26 at 5:26
Do you mean:
getViewTypeCount()
impact getItemViewType()
?– hzy
Mar 26 at 5:26
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55349878%2fandroid-adapter-throw-indexoutofboundsexception-while-scrolling%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Take a look on getCount() and getViewTypeCount(). Is there any relation?
– mustafiz012
Mar 26 at 4:37
in my adapter, the count of viewType isn't more than 16. So getViewTypeCount() return 16.
– hzy
Mar 26 at 5:20
Provide proper code of your adapter.
– Sandeep Insan
Mar 26 at 5:55