0

Some how I managed to break something in my eclipse setup that is breaking butterknife for any new views I try to inject. The "old" views still seem to be fine.

This one works:

    @InjectView(R.id.sign_out_button)
    Button signOutButton;
    

this one does not

    @InjectView(R.id.map_button) 
    Button mapButton;
    

When I add the new field I get this in the generated java file under .apt_generated

   view = finder.findRequiredView(source, 0, "field 'mapButton'"); 

vs this for the "old" field

   view = finder.findRequiredView(source, 2131165280, "field 'signOutButton' and method 

note the 0 vs 2131165280

The error message I get is map_button cannot be resolved or is not a field

And indeed if I look under gen/my_package/R.java there is no entry for map_button, but there is one for sign_out_button.

I have tried cleaning the project and restarting the ide many times. Anyone have any ideas as to what might be wrong?


Solved

Turns out this was a really dumb mistake. I had not added the button to the xml file. Butterknife helps with the code injection but you still need to add the button to the layout file.

Community
  • 1
  • 1
nPn
  • 16,254
  • 9
  • 35
  • 58
  • Have you checked that there's no problems in any of your XML files? If there's an error the R file won't be generated properly, which could be why the sign_out_button isn't being detected – Michael Jul 20 '14 at 19:08
  • I don't see any issue with any of the xml files, and if I try to add a button via xml, it does get added to R.id – nPn Jul 20 '14 at 19:20
  • OK really dumb mistake. I helps if you add the button to in the fragment xml file. – nPn Jul 20 '14 at 19:25
  • Yes that would help :) glad you got it fixed – Michael Jul 20 '14 at 19:29

0 Answers0