How to get Butterknife working?

I am using Butterknife for my android project. I have previously used this, but for some reason it no longer works with the new update.

Here is my setup:

(App Module) build.gradle:

compile 'com.jakewharton:butterknife:8.4.0'

activity:

@BindView(R.id.navigation_pager) ViewPager mViewPager;

/.../

@Override
protected void onCreate(Bundle savedInstanceState) {
    /...
    /...
    ButterKnife.bind(this);

stacktrace:

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.ViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference

What am I missing in order to get Butterknife working?

Thanks.

Answers


You need to add:

classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'

in Project gradle file

And Add:

apt 'com.jakewharton:butterknife-compiler:8.4.0'

and this at top:

apply plugin: 'android-apt'

for butterknife to work

For more info refer this link:https://github.com/JakeWharton/butterknife


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'
}

.`

class ExampleActivity extends Activity {

    @BindView(R.id.navigation_pager) ViewPager mViewPager;
      @Override public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_activity);
        ButterKnife.bind(this);
      viewPager.setAdapter(new CustomPagerAdapter(this));
    }
}

**MAKE SURE TO CALL setAdapter() only after ButterKnife.bind(this);**

Need Your Help

setcookie() always fails "headers already sent" even following the rules on php.net

php setcookie

The relevant peice of code is below. According to php.net I have to make sure there is no output, not even any whitespace. There isn't any. the php tag is the very first tag in the document no whit...

PHP - Failed to open stream : No such file or directory

php require fopen include-path

In PHP scripts, whether calling include(), require(), fopen(), or their derivatives such as include_once, require_once, or even, move_uploaded_file(), one often runs into an error or warning: