I have the following method
private void getdata(String stringfromDate,String stringtoDate ) throws IOException { StringBuilder retVal = new StringBuilder(); URL oracle = new URL("https://xxxxxxxxxxxxxxxx" + stringfromDate +"xxxxxxxx" + stringtoDate +"" ); BufferedReader in = new BufferedReader( new InputStreamReader(oracle.openStream())); String newLine = "\n"; String inputLine; while ((inputLine = in.readLine()) != null) { //System.out.println(inputLine); retVal.append(inputLine).append(newLine); } in.close(); passSting(retVal); } From this i wish to pass retVal to a the method passSting(retVal) so that i can i convert the stringbuilt String to a doc to be treated like an XML doc.
I then do this:
private void passSting(StringBuilder retVal) { Document doc = null; try { doc = (Document) loadXMLFromString(retVal.toString());//pull in the XML data into a new doc } catch (Exception ex) { Logger.getLogger(JavaApplication63.class.getName()).log(Level.SEVERE, null, ex); } } public static org.w3c.dom.Document loadXMLFromString(String xml) throws Exception{ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(xml)); return builder.parse(is); } However i get the following error:
Dec 08, 2015 8:21:51 PM javaapplication63.JavaApplication63 passSting SEVERE: null java.lang.ClassCastException: com.sun.org.apache.xerces.internal.dom.DeferredDocumentImpl cannot be cast to javax.swing.text.Document at javaapplication63.JavaApplication63.passSting(JavaApplication63.java:152) at javaapplication63.JavaApplication63.getdata(JavaApplication63.java:143) at javaapplication63.JavaApplication63.access$000(JavaApplication63.java:47) at javaapplication63.JavaApplication63$1.run(JavaApplication63.java:113) at java.util.TimerThread.mainLoop(Timer.java:555) at java.util.TimerThread.run(Timer.java:505) What am i doing wrong?
No comments:
Post a Comment