I want to call the activity method under certain conditions from singleton. Here is the method itself:
fun workingWithBtn(k: Int) { when (k) { 1 -> { btn_submit_t.showError(); Handler().postDelayed({ this@LoginScr.runOnUiThread { btn_submit_t.hideLoading() btn_submit_t.isEnabled } }, 1000) } 2 -> { btn_submit_t.showSuccess() } 3 -> Handler().postDelayed({ clickCount-- this@LoginScr.runOnUiThread { btn_submit_t.hideLoading() btn_submit_t.isEnabled } }, 1000) } }
In order to call it, I have registered activity in the singleton:
public void setLoginScr(LoginScr loginScr) { this.loginScr = loginScr; }
and in activity:
ms.setLoginScr(LoginScr())
When calling, knocks out with an error:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.Window$Callback android.view.Window.getCallback()' on a null object reference
The essence of the method is that it interacts with the elements of the screen. Judging by the error, I have not initialized the element I need. I tried after initializing by id to try to do something with this view, but I also failed. How can I fix this error?