Classifier 'Error' does not have a companion object, and thus must be initialized here

Viewed 797

I am trying to add LoadStateListener. But I am getting the error "Classifier 'Error' does not have a companion object, and thus must be initialized here" for LoadState.Error . Below is the code snippet.

adapter.addLoadStateListener { loadStates ->
                    when {
                        loadStates.refresh ==LoadState.Error ->{   ----->Gives error here
                            
                        }
                        loadStates.refresh == LoadState.Loading -> {
                            binding.loadingAnimationProgressbar.visibility = View.VISIBLE
                        }
                        loadStates.append == LoadState.Loading -> {
                            binding.loadingAnimationProgressbar.visibility = View.VISIBLE
                        }
                        else -> {
                            binding.loadingAnimationProgressbar.visibility = View.GONE
                        }
                    }

Can someone tell what is the issue here ?

1 Answers

Have a look at the LoadState class.
While the LoadState.Loading is an object, LoadState.Error is a class and thus you must use loadStates.refresh is LoadState.Error syntax for it.

Related