Null Pointer Exception when calling getResources()

前端 未结 3 696
长情又很酷
长情又很酷 2021-01-17 06:08

I\'m making a quiz program for android, and to keep things compatible for different languages, I\'ve put all my quiz questions and labels in my strings.xml file. Basically

3条回答
  •  时光取名叫无心
    2021-01-17 06:44

    You're accessing resources too early, in MainActivity. e.g. field initialization. You can only use your activity as a Context with Resources in onCreate() or later in the activity lifecycle.

    Move the getResources() and getStringArray() calls to onCreate().

提交回复
热议问题