LiveData是抽象的android [英] LiveData is abstract android
本文介绍了LiveData是抽象的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试初始化LiveData对象,但出现错误:"LiveData是抽象的,无法实例化"
I tried initializing my LiveData object and it gives the error: "LiveData is abstract, It cannot be instantiated"
LiveData列表LiveData = new LiveData<>();
LiveData listLiveData = new LiveData<>();
推荐答案
由于它是抽象的(如@CommonsWare说的那样),您需要将其扩展到子类,然后按以下形式重写所需的方法:
Since it is abstract (as @CommonsWare says) you need to extend it to a subclass and then override the methods as required in the form:
public class LiveDataSubClass extends LiveData<Location> {
}
有关更多详细信息,请参见文档
See docs for more details
这篇关于LiveData是抽象的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文