-1

I have an error in Android ButterKnife, using androidx instead of android

java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference build.gradle(project)

classpath 'com.android.tools.build:gradle:3.2.1'

build.gradle(app)

implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'

and error in fragment

@BindView(R.id.recyclerViewProduct)
RecyclerView recyclerViewProduct;
private Unbinder unbinder;

inflating view

View view = inflater.inflate(R.layout.fragment_product, container, false);
 unbinder = ButterKnife.bind(this, view);

I got an error here

recyclerViewProduct.setLayoutManager(mLayoutManager);

and i unbind

 @Override
public void onDetach() {
    unbinder.unbind();
    super.onDetach();
}
Ashik Azeez
  • 404
  • 5
  • 8

2 Answers2

2

Double check if R.id.recyclerViewProduct is defined int the layout file fragment_product.xml.

AJAY PRAKASH
  • 1,110
  • 7
  • 8
0

replace butterknife libs by this

implementation 'com.jakewharton:butterknife:9.0.0-rc1'
annotationProcessor 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
kapt 'com.jakewharton:butterknife-compiler:9.0.0-rc1'
mmfarzaneh
  • 381
  • 1
  • 11