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;








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?










share|improve this question
























  • 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

















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?










share|improve this question
























  • 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













0












0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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

















  • 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












2 Answers
2






active

oldest

votes


















0














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;






share|improve this answer























  • 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



















0














try this might help -



 @Override
public int getItemId(int position)
return position;


@Override
public int getViewTypeCount()
return viewTypes.size();






share|improve this answer























  • Do you mean:getViewTypeCount() impact getItemViewType()?

    – hzy
    Mar 26 at 5:26













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
);



);













draft saved

draft discarded


















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









0














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;






share|improve this answer























  • 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
















0














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;






share|improve this answer























  • 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














0












0








0







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;






share|improve this answer













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;







share|improve this answer












share|improve this answer



share|improve this answer










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


















  • 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














0














try this might help -



 @Override
public int getItemId(int position)
return position;


@Override
public int getViewTypeCount()
return viewTypes.size();






share|improve this answer























  • Do you mean:getViewTypeCount() impact getItemViewType()?

    – hzy
    Mar 26 at 5:26















0














try this might help -



 @Override
public int getItemId(int position)
return position;


@Override
public int getViewTypeCount()
return viewTypes.size();






share|improve this answer























  • Do you mean:getViewTypeCount() impact getItemViewType()?

    – hzy
    Mar 26 at 5:26













0












0








0







try this might help -



 @Override
public int getItemId(int position)
return position;


@Override
public int getViewTypeCount()
return viewTypes.size();






share|improve this answer













try this might help -



 @Override
public int getItemId(int position)
return position;


@Override
public int getViewTypeCount()
return viewTypes.size();







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 26 at 5:03









Sujeet KumarSujeet Kumar

887 bronze badges




887 bronze badges












  • Do you mean:getViewTypeCount() impact getItemViewType()?

    – 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





Do you mean:getViewTypeCount() impact getItemViewType()?

– hzy
Mar 26 at 5:26

















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현