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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

BindView Annotations not working

Hi all.

I'm not sure what's happening here as I'm using the latestversion of ButterKnife.

When I'm using the Bind variables the error states...

can't find method value

I'm stumped. Any ideas? :)

build.gradle
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "uk.co.jonniegrieve.stormy"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.1.1'
    testCompile 'junit:junit:4.12'
    compile 'com.squareup.okhttp3:okhttp:3.6.0'
    compile 'com.google.android.gms:play-services-appindexing:9.8.0'
    compile 'com.jakewharton:butterknife:8.5.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}
main_activity.java
    private CurrentWeather mCurrentWeather;

    @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.summaryLabel) TextView mSummaryLabel;
    @BindView(R.id.iconImageView) ImageView mIconImageView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ButterKnife.bind(this);

        //set up string to query API
        String apiKey = "c967557031449620255ff3c64b443a26";
        double latitude = 37.8267;
        double longitude = -122.4233;

        String forecastURL = "https://api.darksky.net/forecast/" + apiKey + "/" + latitude + "," + longitude;

        if (isNetworkAvailable()) {

            //make a new OkHttpClient object
            OkHttpClient client = new OkHttpClient();

            //new request object - method chaining
            Request request = new Request.Builder()
                    .url(forecastURL)
                    .build();

            //make a request from a Call class
            Call call = client.newCall(request);

            //make and asynchronous call with the enqueue method
            call.enqueue(new Callback() {
                @Override
                public void onFailure(Call call, IOException e) {

                }

                @Override
                public void onResponse(Call call, Response response) throws IOException {
                    try {
                        if (response.isSuccessful()) {
                            String jsonData = response.body().string();

                            Log.v(TAG, jsonData);
                            mCurrentWeather = getCurrentDetails(jsonData);
                        } else {
                            alertUserAboutError();

                        }
                    } catch (IOException e) {
                        Log.e(TAG, "Exception caught", e);
                    } catch (JSONException e) {
                        Log.e(TAG, "JSON Exception Caught", e);
                    }
                }


            });
        } else {
            Toast.makeText(this, getString(R.string.network_unavailable_message),
                    Toast.LENGTH_LONG).show();
            //code challenge:  make into Dialog fragment
        }
        //log to console
        Log.d(TAG, "Main UI code is running!");

    }
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Can anyone help? 2 days through and I can't progress through the course without fixing this.

I've tried

  • Following the teachers notes
  • Following the Github installation readme
  • rewatching the video
  • Messing arround with gradle and the main activity file.

I'm out of ideas.

Ben Deitch
Ben Deitch
Treehouse Teacher

Where does the error happen? Also, is your project on GitHub?

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Ben. Thanks for responding

My project isn't on GitHub, no. Although I have done the Android GitHub workshop, I should probably think about doing that more. :)

The errors are in the @BindValue annotations where you get the ids of the components. i.e. R.id.timeLabel.

The added complication now is I've played around without the build file a bit more so what I'll do is create a repo later on tomorrow (it's late here at the moment) and lost it here as soon as I can :)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Ben Deitch

Thanks again for looking at this for me.

I pushed everything I have from the command line in the end :) You'll find all the errors in the MainActivity.java file and you made need to poke around the gradle files too. Thanks

1 Answer

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

You're using the wrong BindView. Somehow you've created your own BindView interface, and are using that instead of the BindView from ButterKnife. My best guess would be that you used ALT+ENTER on BindView before adding the ButterKnife import, and so instead of adding the import it just created a new BindView interface. Hope that helps!

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi Ben,

A couple of things....

Did I actually link you to my GitHub repo? Did I forget to do that? and if so, how did you work it out? :)

Anyway, when I try to use @BindView annotation, I can only seem to be able to select (uk.co.jonniegrieve.Stormy) or @BindViews (butterknife)

But I get no errors if I manually import import butterknife.BindView; into the MainActivity.

All very confusing but it looks like I've found a way forward?

https://github.com/jg-digital-media/stormy.git

Ben Deitch
Ben Deitch
Treehouse Teacher

Nope, but I figured I'd search your name on GitHub before bugging you about it ;) And yep, looks like you're in the clear!