MaterialSpinner icon indicating copy to clipboard operation
MaterialSpinner copied to clipboard

NPE when clearing selection if no adapter set

Open sebasira opened this issue 3 years ago • 0 comments

When I try to clear the spinnerSelection.

spinner.setSelection(-1)

And then I get:

java.lang.NullPointerException: Attempt to invoke interface method 'int java.util.List.size()' on a null object reference at android.widget.ArrayAdapter.getCount(ArrayAdapter.java:344) at com.tiper.MaterialSpinner$DropDownAdapter.getCount(MaterialSpinner.kt:775) at com.tiper.MaterialSpinner.setSelection(MaterialSpinner.kt:131)

I get the list that would be used for the spinner from the server, and I was setting it to null when no connection or connection error. Now I set to an empty array and it works.

Maybe it's not a bug, but it took me a while to figure out that the problem was the null adapter. Maybe you can throw a different exception? Or clear it anyway even if it has no adapter

sebasira avatar Apr 15 '21 13:04 sebasira