Any ideas why my Android Studio app randomly crashes on setting drawable for ImageView?

I am sure this is a question in vain. But I have coded multiple apps and on each one I get random crashes on updating an image.
I use the findViewById(..).setBackgroundResource(..) method.
Interestingly, when I wait 3s roughfly before updating the images again, I get less crashes.
Even if I space out the image update, I still get some crashes.
This is the loop where the image are updated,

i = 0
while(i!=16)
{
   if(findViewById<TextView>(idsText[i]).text=="$")
   {
      findViewById<TextView>(idsText[i]).text=""
      findViewById<ImageView>(idsImage[i]).setBackgroundResource(R.drawable.box)
   }
   else
   {
      findViewById<ImageView>(idsImage[i]).setBackgroundResource(R.drawable.emptysquare)
   }
      i++
}

I go through this loop every time I press a button to get new letters (images are updated in certain scenarios)
LogCat reader gives me an error :
ViewRootImpl
-> sendUserActionEvent() mView returned

I know this question is very vague, and properly useless to ask. But I have tried being really careful about not having any warnings in my code on new apps I was writing, and I still get these random crashes. So I am really out of ideas..
Kindly,

PS : I isolated all of my code to see where the error comes from, and from isolating and testing scenarios the only part of the code that gives me these crashes is when I update an imageview with a new drawable

  • 1

    Post the stack trace for any crash question

    – 

Leave a Comment