Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android lint error with ?: conditional operator operator

int color = (colorString != null) ?
                someIntReturningMethod(colorString) :
                ContextCompat.getColor(c, R.color.defaultForWhatever);
notificationBuilder.setColor(color);

I get "Should pass resolved color instead of resource id here".

If I remove the ?: and leave color defined as either one, Lint has no problems.

Can I fix this without suppressing any useful warnings? If not, which one do I suppress?

Please no ad-hoc solutions for this problem specifically. I'm asking about ?: confusing lint.

[edit] So, no solution for "?: confusing Lint", in general?

like image 487
kaay Avatar asked Mar 28 '26 02:03

kaay


1 Answers

You can use @ColorInt annotation to annotate that method so lint wont throw a warning

like image 167
JAAD Avatar answered Mar 29 '26 15:03

JAAD



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!