NullPointerException on findViewById() in android

前端 未结 3 1615
我在风中等你
我在风中等你 2020-12-06 18:35

In the following code i get a NullPointerException on lines 9/10 with findViewById().
In my main class I just instantiated an object from this class, to use .getFrom()

3条回答
  •  庸人自扰
    2020-12-06 19:27

    You have to call it from your Activity's onCreate method, as the resources will not have been made available before that point.

    So expanding MByD's answer, in your onCreate method, first call setContentView(), then findViewById().

提交回复
热议问题