Get application context returns null

后端 未结 6 926
隐瞒了意图╮
隐瞒了意图╮ 2020-11-27 18:49

The following schema has been touted as the way to get application context from anywhere within my android app. But sometimes doing MyApp.getContext() returns n

6条回答
  •  死守一世寂寞
    2020-11-27 19:39

    instance is never initialized and so has a default value of null. This means that instance.getContext() will throw a NullPointerException. To fix this, you need to initialize the instance variable.

提交回复
热议问题