Why you chose to reproduce the whole
thing in your post when the error was in line 74, I just can't imagine.
Look at the JavaDocs for Node Interface, appendChild method in the org.w3c.dom package.
You will instantly see that HIERARCHY_REQUEST_ERR can be thrown if the Node is of type Document and you try to append an Element to it.
Sheesh!
Bill