Search code examples
androidandroid-architecture-componentsandroid-livedata

LiveData is abstract android


I tried initializing my LiveData object and it gives the error: "LiveData is abstract, It cannot be instantiated"

LiveData listLiveData = new LiveData<>();


Solution

  • 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