IllegalStateException:Teh specified child already has a parent
FATAL EXCEPTION: main
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child’s parent first.
The error message says what You should do.
// TEXTVIEWif(tv.getParent()!=null)((ViewGroup)tv.getParent()).removeView(tv); // <- fix
layout.addView(tv); // <========== ERROR IN THIS LINE DURING 2ND RUN