Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Weather App (2015) Hooking Up the Model to the View Using Butter Knife for Views

Billy Lardizabal
Billy Lardizabal
5,017 Points

@InjectView Not Working

In the current version 7 of Butter Knife, InjectView throws an error. However, when replacing the 7 with version 6, it works. Was just wondering if there was an updated method to go with Butter Knife 7.

4 Answers

Seth Kroger
Seth Kroger
56,413 Points

It's renamed to @Bind as well as inject() to bind(). You can see the updated docs for the new version here: http://jakewharton.github.io/butterknife/

A lot of the annotations and functions were renamed in the jump from version 6 to 7 so it might be a better idea to use the same version Ben uses to avoid confusion.

In addition import this element before replacing injectView and inject width Bind:

import butterknife.ButterKnife;

import butterknife.Bind;

Fidel Torres
Fidel Torres
25,286 Points

Hello There

   //This is the code are given in the Class Notes
  @InjectView(R.id.timeLabel) TextView mTimeLabel;
  @InjectView(R.id.temperatureLabel) TextView mTemperatureLabel;
  @InjectView(R.id.humidityValue)  TextView mHumidityValue;
  @InjectView(R.id.precipValue) TextView mPrecipValue;
  @InjectView(R.id.summaryLabel) TextView mSummaryLabel;
  @InjectView(R.id.iconImageView) ImageView mIconImageView;


  //And this is what should you use according to the update in the ButterKnife Library
  @Bind(R.id.timeLabel) TextView mTimeLabel;
  @Bind(R.id.temperatureLabel) TextView mTemperatureLabel;
  @Bind(R.id.humidityValue)  TextView mHumidityValue;
  @Bind(R.id.precipValue) TextView mPrecipValue;
  @Bind(R.id.summaryLabel) TextView mSummaryLabel;
  @Bind(R.id.iconImageView) ImageView mIconImageView;

For more info check the Docs

Oussama DJEDIDI
Oussama DJEDIDI
4,599 Points

I think this last answer should marked as best answer for help