This will crash:
if (isBonus.contains(v)) {
isBonus.remove(new Integer(v));
lpb.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
}
Where v is an int. Contains(int) is fine, but remove(int) aint.
This will crash:
if (isBonus.contains(v)) {
isBonus.remove(new Integer(v));
lpb.getBackground().setColorFilter(Color.WHITE, PorterDuff.Mode.MULTIPLY);
}
Where v is an int. Contains(int) is fine, but remove(int) aint.
Stack trace?
It very well might be something obvious like ConcurrentModificationException, but from those 4 lines of code it would be hard to tell.
List.remove(Object) and List.remove(index) are easily confused in the case of List
Your (supposedly) original code is extremely error prone, Dalvik or not:
int v = ...;
if (isBonus.contains(v)) { // will be boxed to an Integer VALUE
isBonus.remove(v); // removes arbitrary value at INDEX v
}
I’m not looping through the collection… Wrapping the int in an Integer fixes the issue.
Edit: replying to pandemoniumhun, but Riven has the answer.
Which issue…
Ah…
Dalvik, I suck :’(
FYI: I configure Eclipse to flag auto-boxing/unboxing as an error.
I do too in IntelliJ, but I am using AIDE at the moment, it is not quite as richly featured.
Hi
Does it crash with ART too?
Personally, I prefer staying far from auto-boxing even with J2SE. I already had a problem when using it with ternary operators, it discouraged me. I use Integer.valueOf(int). I’m explicit. If I spend too much time in understanding some lines of code, I throw in the towel.
That’s why in my pretty Array class it’s removeValue(T value, boolean identity) and removeIndex (int index).
Don’t worry, Dalvik still sucks anyway.
Cas