Butterknife: ClassCastException: Symbol$VarSymbol …
The other day I decided to update my Butterknife from 6.x.x to 7.x.x. Immediately I noticed some refactoring (e.g. @InjectView became @Bind). I updated my code and got build (from Android Studio’s “make”). Unfortunately, when I tried to test it, I got:
java.lang.ClassCastException: com.sun.tools.javac.code.Symbol$VarSymbol cannot be cast to javax.lang.model.element.ExecutableElement
from Dagger (yes, I’m still using 1.x.x). Annoying to say the least.
It turns out that I forgot to refactor a couple of files from my code and Dagger failed to parse dome Butterknife code (I guess?). My solution was to look for butterknife in all my java files (the import statement for example) and take all the found files (not too many in all fairness) by hand.
So no, it’s not a bug in either libraries, but in my/your code somewhere.
Be careful with the refactored APIs in 3rd party libraries.
A little experiment: If you find this post and ad below useful, please check the ad out :-)