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

Andrew Pritykin
Andrew Pritykin
6,574 Points

ButterKnife.bind(this, ???)

When trying to bind, Android studio does not like (this) to be by itself.

Ive seen in the forums someone say to write ButterKnife.bind(this,view) but when I go to type view, it gives me options like iconImageView.

I even tried to use the depreciated Butterknife 6.1.0 using Butterknife.inject(this) and it says it cannot resolve

    @BindView(R.id.timeLabel) TextView mTimeLabel;
    @BindView(R.id.temperatureLabel) TextView mTemperatureLabel;
    @BindView(R.id.humidityValue) TextView mHumidityValue;
    @BindView(R.id.precipValue) TextView mPrecipValue;
    @BindView(R.id.summaryTextView) TextView mSummaryLabel;
    @BindView(R.id.iconImageview) ImageView mIconImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Import view variables
        ButterKnife.bind(this,view);

2 Answers

Andrew Pritykin
Andrew Pritykin
6,574 Points

Looks like there was something wrong with Android Studio. What I did was I went to File -- invalidate Caches and restart. When Android Studio restarted everything worked fine.

Seth Kroger
Seth Kroger
56,413 Points

No, inside an Activity ButterKnife.bind(this) is correct. bind(this, view) is for when you aren't in an Activity. Can you more specific what "doesn't like" mean?

Andrew Pritykin
Andrew Pritykin
6,574 Points

It is giving me an error when I hover over it saying cannot find method 'bind(my activity name)'