As its name implies, addAndReplaceElement
find the element and replaces it with the given widget. Once you called addAndReplaceElement
once for an element, that one element is gone, so the second call obviously won't find it, resulting in the NoSuchElementException
you're seeing.
If you ever want to replace your widget with another, then you need to wrap it in an element (i.e. call add
instead of addAndReplaceElement
), and use remove
to remove the previous widget.