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 Plugging in the Data

Still getting "java.lang.NullPointerException" error even after following every workaround

Error when running the app "java.lang.NullPointerException" is still occurring even after following every workaround listed in the questions. Can this course be updated to not teach 3rd party libraries?

Seth Kroger
Seth Kroger
56,413 Points

NullPointerException is a rather ubiquitous error that can be caused by any number of reasons. The cause of your NullPointerException may not be the same as someone else's on the same project. Why don't we start with when the crash occurred and look at your code from there.

Rajesh Kantipudi
Rajesh Kantipudi
13,941 Points

Hey, Try to update your project and app level Gradle files by adding these lines. It worked perfectly for me.

App level Gradle file:

apply plugin: 'com.android.application' apply plugin: 'android-apt'

android { compileSdkVersion 24 buildToolsVersion "24.0.1" defaultConfig { applicationId "com.test.stormy" minSdkVersion 16 targetSdkVersion 24 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:24.2.1' testCompile 'junit:junit:4.12'

compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'com.jakewharton:butterknife:8.4.0'
apt 'com.jakewharton:butterknife-compiler:8.4.0'

}

Root or Project level Gradle file:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.2.0' classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } }

allprojects { repositories { jcenter() } }

task clean(type: Delete) { delete rootProject.buildDir }

4 Answers

Michael Nock
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Michael Nock
Android Development Techdegree Graduate 16,018 Points

The GitHub page is this link:
https://github.com/JakeWharton/butterknife#download

Here are the important bits:

Configure your project-level build.gradle to include the 'android-apt' plugin:

 buildscript {
   repositories {
     mavenCentral()
    }
   dependencies {
     classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
   }
 }

Then, apply the 'android-apt' plugin in your module-level build.gradle and add the Butter Knife dependencies:

 apply plugin: 'android-apt'

 android {
   ...
 }

 dependencies {
   compile 'com.jakewharton:butterknife:8.4.0'
   apt 'com.jakewharton:butterknife-compiler:8.4.0'
 }

The page here:
http://jakewharton.github.io/butterknife/
... doesn't mention needing to include the android-apt plugin in your project build.gradle file.

You may want to initialize the textViews the old fashion way in the onCreate() method. And if that works try with ButterKnife.

Seth Kroger
Seth Kroger
56,413 Points

You all seem to be assuming the issue is related to ButterKnife when there is no code or stacktrace posted that would indicate that. That may not necessarily be the case because there are plenty of things that can cause a NullPointerException.

Javier Mera
Javier Mera
16,472 Points

Just like Rajesh pointed out, follow the instructions on how to setup both build.gradle Project and Module, under ButterKnife's github page. I had the same issue, and got fixed once I updated everything according to their instructions.

Mint Milano
Mint Milano
3,114 Points

Even I got the null exception error trying really hard to eliminate it..pls help