Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attempt to invoke virtual method GapWorker.remove(RecyclerView)' on a null object reference

I am getting this error on Recyclerview in production , but don't know exactly in which class

What I did

Google it and found https://issuetracker.google.com/issues/38375597 , where people said its android bug and fixed in support lib 27.1.0

I updated my support lib and buildVersion

support           : '27.1.0',
buildToolsVersion: '27.0.3',
compileSdkVersion : 26,

Still this crash occurrs

error log

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.GapWorker.remove(android.support.v7.widget.RecyclerView)' on a null object reference
       at android.support.v7.widget.RecyclerView.onDetachedFromWindow(RecyclerView.java:2534)
       at android.view.View.dispatchDetachedFromWindow(View.java:13586)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2849)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2846)
       at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:3076)
       at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5709)
       at android.view.ViewRootImpl.die(ViewRootImpl.java:5686)
       at android.view.WindowManagerGlobal.removeViewLocked(WindowManagerGlobal.java:387)
       at android.view.WindowManagerGlobal.removeView(WindowManagerGlobal.java:342)
       at android.view.WindowManagerImpl.removeViewImmediate(WindowManagerImpl.java:116)
       at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3893)
       at android.app.ActivityThread.access$1500(ActivityThread.java:164)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1473)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:159)
       at android.app.ActivityThread.main(ActivityThread.java:5461)
       at java.lang.reflect.Method.invoke(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:372)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:964)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:759)
like image 811
karthik kolanji Avatar asked Oct 28 '22 13:10

karthik kolanji


1 Answers

This issue usually occurs when no LayoutManager was provided for the RecyclerView. You can do it like so

final LinearLayoutManager layoutManager = new LinearLayoutManager(context);
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
like image 175
MK Vimalan Avatar answered Nov 15 '22 06:11

MK Vimalan