JavaPoet + Android Studio "addModifiers(Modifier) cannot be applied to Modifier"
Asked Answered
D

1

11

I've built an annotation processor for my Android project that builds a source file using JavaPoet. However, every time I need to call addModifiers on any JavaPoet object, Android Studio flags it as an error. It will say either

Cannot resolve method addModifiers(javax.lang.model.element.Modifier)

or

addModifiers(javax.lang.model.element.Modifier) cannot be applied to javax.lang.model.element.Modifier

depending on which object I'm calling the method on. I've checked many times that the two fully qualified class names match perfectly. These methods in JavaPoet use VarArgs arguments, but that shouldn't make a difference since I'm compiling to Java 7.

Now here's the kicker: The package compiles just fine, and creates my source file. It only gives me the error in the IDE, not when javac runs. The modifiers are correct in the generated file.

So I guess what I want answered is: How do I get rid of the IDE error, and who do I report this to? Is this a JavaPoet issue, an Android Studio issue, or an IntelliJ issue, or something I haven't considered yet?

Descombes answered 26/9, 2015 at 20:11 Comment(2)
I'm having the same issue, have you found a solution?Cheeky
look at my answer can workProfusive
P
0

this question is like To this one How to get a reference to Modifier.PUBLIC that can not be applied in builder in MethodSpec's methodBuilder for JavaPoet

You just only add this code to your build.gralde

implementation 'org.checkerframework:checker:2.1.10'

that error will gone.the error is that andorid studio bugs,

this error is same to belows

you can reference belows

first :https://github.com/square/javapoet/issues/632

error gone by add this

Profusive answered 27/11, 2019 at 3:21 Comment(1)
This does work because the checkerframework contains all of the javax.lang.model directly in the jar. Note this could potentially cause problems with inconsistent versions, so use with care.Pyorrhea

© 2022 - 2024 — McMap. All rights reserved.