• 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

I have an if statment that if the condition is met, I do a setImageResource() on an ImageView and occasionaly it works, but most of the time it force closes after the fact. If I comment out the setImageResource() it will do all the other calculations and such fine. Can anyone shed some light on this?
 
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.

 
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).
 
Back
Top Bottom