Fix NullPointerException in widget.

I'm not sure how to reproduce the issue, but I suppose this change should fix #401.