Answer the question
In order to leave comments, you need to log in
What is the problem in android studio?
Help solve the problem
Answer the question
In order to leave comments, you need to log in
You are trying to execute code outside of runtime.
Any program always has an entry point, in activation the entry point is onCreate (), the system starts executing the commands written in the onCreate () method sequentially. Do not forget that this is still Android, so the system will make some calls on its own (onResume(), for example).
Everything is correctly done with addListenerOnButton (), because the method call is in the body of another method.
Further, the call of the listener setup method is not in the body of another method, but in the body of the class (in which the description is made, but not the call). You just need to put .setOnClickListener() in the body of the AddListenerOnButton() method
Move the selection to a lifecycle method like OnCreate(Bundle savedInstanceState) .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question