• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Problems with setImageResource() on in if statement

Ok after posting this I think I found the solution. So I added the code as follows:

Before:
}​
else if (monstID < 4000) {

monstName = "Shewanadon";
imgMonster.setImageResource(R.drawable.shewanadon);

After:
}​
else if (monstID < 4000) {
monstName = "Shewanadon";
imgMonster = (ImageView) this.findViewById(R.id.imgMonsterPic);

imgMonster.setImageResource(R.drawable.shewanadon);


Not sure why that worked out like that but it did. Before I declared the ImageView outside the If statement and thats when it failed.

 
Upvote 0
Off the cuff first guess is that you're image might be too large, causing an OutOfMemoryException.

But, cp1 is right: if you want to really know what's causing the error - which could really "help us help you" - then run the program and check the LogCat window in the Debug view (if you're using Eclipse) and tell us what the error is that terminates the program. If you can't figure out which error it is exactly, then just copy a screenshot which covers all the error logs in your LogCat window (hint: they're red).
 
  • Like
Reactions: jdizzle1988
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones