Android: findViewById returns Null even if is after setContentView

前端 未结 2 606
南方客
南方客 2020-12-12 03:50

Here\'s my code in LoginActivity:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R         


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 04:32

    Try declaring the button inside onCreate, rather than declaring it outside of it (which is what I'm assuming you're doing).

    Oh, and if you haven't tried this already, use "VIEW.findViewById(R.id.loginButton)", rather than just "findViewById(R.id.loginButton);". I think that's more likely your problem; I forget about it a lot too.

提交回复
热议问题