Null pointer Exception - findViewById()

后端 未结 10 2685
情歌与酒
情歌与酒 2020-11-21 04:16

Can anyone help me to find out what can be the issue with this program. In the onCreate() method the findViewById() returns null for all ids and th

10条回答
  •  无人及你
    2020-11-21 05:12

    In Android, findViewById(R.id.some_id) works when you are finding view in the layout set.

    That is, if you have set a layout say:

    setContentView(R.layout.my_layout);
    

    Views can be found only in this layout (my_layout).

    In your code layout1, layout2, layout3 all are three different layouts and they are not set to the activity.

提交回复
热议问题