1

I use WebView to display a SVG image and I'd like to add another SVG image as a child of one of the nodes of the original SVG (similar to what is described here using batik: How do I superimpose one SVG image onto another using Apache Batik?). Then I get a ClassCastException.
Here is where i use the base SVG image:

final String svg = "background.svg";
final uri = Paths.get(svg).toAbsolutePath().toUri();
WebView root = new WebView();
root.getEngine().load(uri.toString());

The SVG dislays correctly.
Then I have this piece of code, executed when a user press a button, that tries to add another image to the parent SVG:

File anotherFile = new File("over.svg");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(anotherFile);

Node e = root.getEngine().getDocument().importNode(doc.getDocumentElement(), true);
root.getEngine().getDocument().appendChild(e);

The following exception occurs when trying to use importNode:

java.lang.ClassCastException:
com.sun.org.apache.xerces.internal.dom.DeferredElementImpl cannot be cast to
com.sun.webkit.dom.NodeImpl
Community
  • 1
  • 1
dawww
  • 371
  • 1
  • 4
  • 16

0 Answers0