Search code examples
javaandroidbuttonclickbutterknife

OnClick ButterKnife, nothing happens


I'm trying to use ButterKnife to onClick. I did the code bellow and nothing happens, I've watched tutorials all over the internet, and they do the same thing as I did.

Here is the code

@BindView(R.id.startButton) protected ImageButton mStartButton;

@OnClick(R.id.startButton)
public void startTest(){
    Toast.makeText(this, "testing", Toast.LENGTH_LONG).show();
}

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

    ButterKnife.bind(MainActivity.this);

}

And if I put the method startTest(); inside the OnCreate, the toast is called when the app runs for the first time, what shows that the ButterKnife is working. But I need that to happen only when the button is clicked.

Thanks


Solution

  • You mentioned that you have compile 'com.jakewharton:butterknife:8.4.0' in your build.gradle file. I think you may be missing the corresponding compiler. Add this to your dependencies section:

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