【发布时间】:2021-09-22 15:50:35
【问题描述】:
我正在尝试用 Kotlin 做单例模式,但我不明白为什么我在这里得到空指针异常
object AppController : Application() {
private val queue: RequestQueue = Volley.newRequestQueue(applicationContext)
fun getRequestQueue(): RequestQueue {
return queue
}
}
在我打电话的主要活动中:
private val controller = AppController
private val queue = AppController.getRequestQueue()
感谢您的帮助。对不起。我不确定为什么代码格式不正确。
【问题讨论】:
-
您添加的代码sn-ps不可见,我只能看到“...”,您可以更新您的帖子并确保代码在预览中可见吗?