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

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Where to go from here with Android

Hi everyone,

So.. .to cut a long story short, I've been having a lot of trouble following along with the great new Android Lists and Adapters course. And I ended up deleting my progress and starting afresh... the idea being that I could wipe the slate clean and follow along, eliminating what might have been causing the errors previously.

Following on using my own packages, rather than the com.teamtreehouse.stormy

Now, I've started refactoring my packages in this video , and it's causing MainActivity.java to error at the point where we call the binding.setWeather(displayWeather); function and I don't know why. But it seems like the refactoring isn't getting through to that function so its still pointing to an invalid location.

This and so many annoying quirks and glitches.

I'm trying to compare with the project files for the video which runs without errors and can't see where I'm going wrong.

I've lost a lot of my confidence. My main question is this.... am I doing the right thing following on from my version of the previous Weather App course? I might try all this again following on from the project files from this video but I'd like to think I'm able to run on y own steam as much as possible so to speak.

Ben Deitch
Ben Deitch
Treehouse Teacher

Hey Jonathan! Is your project on GitHub? I can take a look and let you know if it works on my system.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Ben,

Thanks for replying to the topic.

As I mentioned I have been trying again with the project and restarted from the first set of project files from the course.

Initially, I didn't want to do this as I wanted to build it up using my own package in Android Studio.

So I ended up fixing the error I described in this post. That's okay now. But came back to the thing that made me restart in the first place.

The ActivityHourlyForecastBinding binding isn't picking up in Android Studio. It can't be imported with the quickfix or manually typing it in. Basically as described in my post here.

https://teamtreehouse.com/community/activityhourlyforecastbinding-not-working-in-android-312

So when I'm typing in my import

import com.teamtreehouse.stormy.databinding. ...

I should be seeing an option to fill in ActivityHourlyForecastBinding as an autofill but I've never been able to see this. I only wish I knew why.

My Repo is here :)

https://github.com/jg-digital-media/stormy_list_tth

Thank you again!!

2 Answers

Ben Deitch
STAFF
Ben Deitch
Treehouse Teacher

Hmm it looks like your 'activity_hourly_forecast.xml' is a little different than the one in the project files. I think adding the 'data' tag is what triggers that import to get created. Hope that helps!

<?xml version="1.0" encoding="utf-8"?>
<layout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools">
    <data>
        <variable
            name="hour"
            type="com.teamtreehouse.stormy.Weather.Hour"/>
    </data>
    <android.support.constraint.ConstraintLayout
        android:id="@+id/coordinatorLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/appBackground"
        tools:context=".ui.HourlyForecastActivity">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/hourlyListItems"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>
    </android.support.constraint.ConstraintLayout>
</layout>
Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Thanks again for replying.

Unfortunately, it hasn't work. I think doing this causes a conflict with the hourly_list_item.xml file, as such these errors show up on project sync.

null    
C:/filepathtoproject    
app/src/main/res    
layout/activity_hourly_forecast.xml 
error: duplicate attribute. 

This is where the hour variable is declared in the video. And the autofill still doesn't show up either.

Ben Deitch
Ben Deitch
Treehouse Teacher

Well that's strange. Updating 'activity_hour_forecast.xml' fixed the import issue for me*. Last thing I can think of would be to download Ken's project from the project files, and try to run that. If it runs, you should be able to find what's different about it.

*Though I did have to change HourlyOnClick -> hourlyOnClick at the bottom of 'activity_main.xml' before it would run.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Hi Ben,

I can't tell you how many hours I've lost trying to do just that.. delve into different versions of the project to find what's wrong. I do know that we don't actually add the hour variable to activity_hourly_forecast.xml during the course videos and it's only later on we see that this has been added to that file. And if I do have both of these files changed to include the Data Binding variable, things start to happen to the Gradle build.

I'm going to keep at it, although until I find the culprit, I'm at a loss. I'll update the post if I ever get to the bottom of it :)

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Or... I could just carry on from Ken's project files from S3V1 which seem to be working but I'll consider that my last option. :)

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

I've done it!!!

I'm still not entirely sure how...

But I used git to revert back to my last working state... so before the "Activity" video of the course.

I then built up the activity_hourly_forecast.xml file per your suggestion Ben... which then brought back up the duplicate Android attribute error on project synch.

It all changed when I copied the version of activity_hourly_forecast.xml from Ken's working project files. From that moment on, I was able to generate the ActivityHourlyForecastBinding in HourlyForecastActivity.java

import com.teamtreehouse.stormy.databinding.ActivityHourlyForecastBinding

Suddenly the duplicate attribute error disappeared and I was able to click the Hourly list button. I did need to change the onclick attribute which was an easy fix. I do wish I could spot what the actual difference was but at this point, I'll take it for what it is.

This is a relief and a massive win for persistence, I think.

I hope this thread will help someone else someday

Ben Deitch
Ben Deitch
Treehouse Teacher

Woohoo! Glad to hear you got it solved!