如何在AndroidViewModel中初始化MutableLiveData的空数组?

如何在AndroidViewModel中初始化MutableLiveData的空数组?,android,viewmodel,android-viewmodel,Android,Viewmodel,Android Viewmodel,我尝试创建一个提供字符串数组的viewModel。 但是当我尝试对LiveData对象执行.postValue时,我遇到了这个错误 Array initializer is not allow here. 我的视图模型是这样的 那么我如何解决这个问题呢 谢谢 应该是这样:((MutableLiveData)this.filtertests).postValue(新字符串[]{})应该是这样:((MutableLiveData)this.filtertests).postValue(新字符串[

我尝试创建一个提供字符串数组的viewModel。 但是当我尝试对LiveData对象执行.postValue时,我遇到了这个错误

Array initializer is not allow here.
我的视图模型是这样的

那么我如何解决这个问题呢


谢谢

应该是这样:
((MutableLiveData)this.filtertests).postValue(新字符串[]{})

应该是这样:
((MutableLiveData)this.filtertests).postValue(新字符串[]{})

用于初始化变量。您可以使用用于初始化变量的新字符串[0]
创建空数组。您可以使用
新字符串[0]