There is an error I am facing that can't find the source of or any solution for it.
From my MainActivity I start another activity using startActivityForResult but later in the MainActivity's onActivityResult when I want to update a constraint layout's visibility the following error happens, because the view becomes null. Unfortunaltely I can't reproduce the error, but it is happening on multiple devices according to crashlytics and I have no idea how to fix it.
Just adding an if check wouldn't solve this problem, cause I assume not only this view becomes null.
I use Butterknife to bind my views in the activity, I dont know if it is connected to this:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Crashlytics log:
Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.constraintlayout.widget.ConstraintLayout.setVisibility(int)' on a null object reference
at com.examaple.myapp.home.MainActivity.hideView(MainActivity.java:506)
at com.examaple.myapp.home.MainActivity.onActivityResult(MainActivity.java:331)
at android.app.Activity.dispatchActivityResult(Activity.java:7762)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4603)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4652)
at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:49)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1948)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:214)