findViewById returns null

后端 未结 4 2100
说谎
说谎 2020-11-22 09:59

I have code:

public class HelloWorld extends Activity {

private Button buttonOk;
private Button buttonCancel;

private OnClickListener buttonOkListener = ne         


        
4条回答
  •  天命终不由人
    2020-11-22 10:41

    I'm not 100% sure but you are calling the findviewbyid's in the class initialisation. I think this code is called before the onCreate method so the view's cannot be found. Initializing the listeners in the oncreate method should work.

提交回复
热议问题