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 Animations and Transitions Animations Basics Property Animation

Semen Zadorozhnyi
Semen Zadorozhnyi
8,515 Points

Clone project, did changes, not starting

I did all sdk/dependency changes to allow android to run project on VD but getting this exception:

FATAL EXCEPTION: main
                  Process: com.jimulabs.googlemusicmock, PID: 4309
                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jimulabs.googlemusicmock/com.teamtreehouse.albumcover.AlbumListActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                      at android.app.ActivityThread.-wrap12(ActivityThread.java)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                      at android.os.Handler.dispatchMessage(Handler.java:102)
                      at android.os.Looper.loop(Looper.java:154)
                      at android.app.ActivityThread.main(ActivityThread.java:6077)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.RecyclerView.setLayoutManager(android.support.v7.widget.RecyclerView$LayoutManager)' on a null object reference
                      at com.teamtreehouse.albumcover.AlbumListActivity.populate(AlbumListActivity.java:61)
                      at com.teamtreehouse.albumcover.AlbumListActivity.onCreate(AlbumListActivity.java:30)
                      at android.app.Activity.performCreate(Activity.java:6662)
                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
                      at android.app.ActivityThread.-wrap12(ActivityThread.java) 
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                      at android.os.Looper.loop(Looper.java:154) 
                      at android.app.ActivityThread.main(ActivityThread.java:6077) 
                      at java.lang.reflect.Method.invoke(Native Method) 
                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865) 
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Semen Zadorozhnyi
Semen Zadorozhnyi
8,515 Points

build.gradle file

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.jimulabs.googlemusicmock"
        minSdkVersion 19
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    lintOptions {
        disable 'InvalidPackage'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.jimulabs.mirrorsandbox:mirror-sandbox:0.2.1'
    compile 'com.android.support:palette-v7:25.1.1'
}
Semen Zadorozhnyi
Semen Zadorozhnyi
8,515 Points

Part of code where exception appears:

public class AlbumListActivity extends Activity {

    @BindView(R.id.album_list) RecyclerView mAlbumList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_album_list);
        setupTransitions();

        ButterKnife.bind(this);
        populate();
    }

....

private void populate() {
        StaggeredGridLayoutManager lm = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        mAlbumList.setLayoutManager(lm);

        final int[] albumArts = {
                R.drawable.mean_something_kinder_than_wolves,
                R.drawable.cylinders_chris_zabriskie,
                R.drawable.broken_distance_sutro,
                R.drawable.playing_with_scratches_ruckus_roboticus,
                R.drawable.keep_it_together_guster,
                R.drawable.the_carpenter_avett_brothers,
                R.drawable.please_sondre_lerche,
                R.drawable.direct_to_video_chris_zabriskie };

        RecyclerView.Adapter adapter = new RecyclerView.Adapter<AlbumVH>() {
            @Override
            public AlbumVH onCreateViewHolder(ViewGroup parent, int viewType) {
                View albumView = getLayoutInflater().inflate(R.layout.album_grid_item, parent, false);
                return new AlbumVH(albumView, new OnVHClickedListener() {
                    @Override
                    public void onVHClicked(AlbumVH vh) {
                        int albumArtResId = albumArts[vh.getPosition() % albumArts.length];
                        Intent intent = new Intent(AlbumListActivity.this, AlbumDetailActivity.class);
                        intent.putExtra(AlbumDetailActivity.EXTRA_ALBUM_ART_RESID, albumArtResId);

                        ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                                AlbumListActivity.this, vh.albumArt, "albumArt");
                        startActivity(intent, options.toBundle());
                    }
                });
            }

            @Override
            public void onBindViewHolder(AlbumVH holder, int position) {
                holder.albumArt.setImageResource(albumArts[position % albumArts.length]);
            }

            @Override
            public int getItemCount() {
                return albumArts.length * 4;
            }

        };
        mAlbumList.setAdapter(adapter);
    }

...
}

3 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Ouch - ButterKnife added another dependency that is causing this issue. In addition to the line you already updated in your build.gradle file, you need to add another, so it looks like this below. Notice the new "annotationProcessor" line at the bottom:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.jakewharton:butterknife:8.4.0'
    compile 'com.jimulabs.mirrorsandbox:mirror-sandbox:0.2.1'
    compile 'com.android.support:palette-v7:25.1.1'
    annotationProcessor 'com.jakewharton:butterknife-compiler:8.5.1'
}

I need to figure out how to address this in the course. Sorry for your frustration, and thanks for the heads up about this issue.

Santiago Herrero
Santiago Herrero
21,105 Points

Could you add it to your repo at Github please?

I have changed as you did here my depencies and it keeps crashing, this is what I get -> https://i.gyazo.com/c78e0d1936e5165d5006ed3fe3bd0297.png

Many thanks in advance

Scott Junner
Scott Junner
9,010 Points

I think a note in the teachers notes would be enough. There seems to be a few steps to get the project running with updated dependencies.

  1. Update the compile and build tools versions in app.gradle.build
  2. Update ALL dependency versions and add extra annotationProcessor for Butterknife in app.gradle.build
  3. Update dependencies classpath in build.gradle
  4. Update distributionUrl in gradle-wrapper.properties
  5. Clench jaw tightly and growl quiet, low and menacing.
  6. Go through project .java files to change "@Bind" to "@BindView", including import statement

Should be good after that.

P.S. 7. Unclench jaw. (This is vital because leaving the jaw clenched will cause pizza eating errors.)

Orion Wolf-Hubbard
Orion Wolf-Hubbard
4,906 Points

i think its @BindView now, I'm having a hard time getting up and running too

Nataly Rifold
Nataly Rifold
12,431 Points

Hi, So.... I updated every thing because it didn't want to work... but I get this:

Manifest merger failed : Attribute application@appComponentFactory value=(android.support.v4.app.CoreComponentFactory) from [com.android.support:support-compat:28.0.0] AndroidManifest.xml:22:18-91 is also present at [androidx.core:core:1.0.0] AndroidManifest.xml:22:18-86 value=(androidx.core.app.CoreComponentFactory). Suggestion: add 'tools:replace="android:appComponentFactory"' to <application> element at AndroidManifest.xml:5:5-23:19 to override.

from build.gradle app file

android { compileSdkVersion 28 buildToolsVersion "28.0.3"

defaultConfig {
    applicationId "com.jimulabs.googlemusicmock"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
lintOptions {
    disable 'InvalidPackage'
}

}

dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:recyclerview-v7:28.0.0' implementation 'com.jimulabs.mirrorsandbox:mirror-sandbox:0.2.1' implementation 'com.android.support:palette-v7:28.0.0' implementation 'com.jakewharton:butterknife:10.0.0' implementation 'com.google.android.material:material:1.0.0' annotationProcessor 'com.jakewharton:butterknife-compiler:10.0.0' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' }

from build.gradle model file

buildscript { repositories { google() jcenter() } dependencies { classpath 'com.android.tools.build:gradle:3.3.0'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects { repositories { google() jcenter() maven { url "https://maven.google.com" } } }

and I changed the distributionUrl in wrapper properties distributionUrl=https://services.gradle.org/distributions/gradle-4.10.1-all.zip

sooooo help!

and please update the course files in GitHub or put instruction how to make it work.