Post by chriscrawford on Mar 3, 2016 8:36:33 GMT -8
This particularly angers: they issue a new version of the Java engine, and it breaks code that previously worked just fine, and it breaks in a manner that's impossible to decipher. Here's the complete method that breaks now:
This code worked just fine when I wrote it last May. But now when it runs, it triggers the last CATCH ("can't transform the DOM model"). The error message associated with this is "Result object passed to ''{0}'' is invalid." I searched for the error message on the web and came up with just one example, which didn't help at all.
I'm stuck. I can't figure out how to fix this damn thing. I'll try asking about it on a board, but I am not optimistic that I'll get an answer that I can understand.
public static void saveExpressions(FaceDisplay fd) {
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream("res/FaceRes/expressions.xml");
} catch (Exception e) { }
DocumentBuilder builder = null;
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Element expressionSet, express, feature, point;
try {
builder = factory.newDocumentBuilder();
}
catch (ParserConfigurationException e) {
e.printStackTrace();
}
Document doc = builder.newDocument();
// write to doc here.
expressionSet = doc.createElement("expressionSet");
doc.appendChild(expressionSet);
expressionSet.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
expressionSet.setAttribute("xsi:noNamespaceSchemaLocation", "expressionSet.xsd");
ArrayList<Expression> expressions = fd.getExpressions();
for (Expression fe:expressions) {
express = doc.createElement("expression");
expressionSet.appendChild(express);
express.setAttribute("aLabel", fe.getName());
express.setAttribute("attack", String.valueOf(fe.getAttack()));
express.setAttribute("bSustain", String.valueOf(fe.getSustain()));
express.setAttribute("decay", String.valueOf(fe.getDecay()));
for (int j=0; (j<Expression.FeatureCount); ++j) {
feature = doc.createElement("feature");
express.appendChild(feature);
feature.setAttribute("name", fe.getFeature(j).getLabel());
feature.setAttribute("size", String.valueOf(fe.getFeature(j).getSize()));
feature.setAttribute("participation", String.valueOf(fe.getFeature(j).getParticipation()));
for (int k=0; (k<fe.getFeature(j).getSize()); ++k) {
point = doc.createElement("point");
point.setAttribute("rightX", String.valueOf(fe.getFeature(j).getRightX(k)));
point.setAttribute("rightY", String.valueOf(fe.getFeature(j).getRightY(k)));
point.setAttribute("rightLineThickness", String.valueOf(fe.getFeature(j).getRightLineThickness(k)));
point.setAttribute("leftX", String.valueOf(fe.getFeature(j).getLeftX(k)));
point.setAttribute("leftY", String.valueOf(fe.getFeature(j).getLeftY(k)));
point.setAttribute("leftLineThickness", String.valueOf(fe.getFeature(j).getLeftLineThickness(k)));
feature.appendChild(point);
}
}
}
// *** Transform the DOM model to a text string ***
try {
TransformerFactory tf = TransformerFactory.newInstance();
tf.setAttribute("indent-number", new Integer(4)); //
Transformer transformer = tf.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
// initialize StreamResult with File object to save to file
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outputStream);
transformer.transform(source,result);
}
catch (TransformerConfigurationException e) {
System.out.println("can't tranform the DOM model");
}
catch (TransformerException e) {
System.out.println("can't transform the DOM model");
}
}
This code worked just fine when I wrote it last May. But now when it runs, it triggers the last CATCH ("can't transform the DOM model"). The error message associated with this is "Result object passed to ''{0}'' is invalid." I searched for the error message on the web and came up with just one example, which didn't help at all.
I'm stuck. I can't figure out how to fix this damn thing. I'll try asking about it on a board, but I am not optimistic that I'll get an answer that I can understand.