xml-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Wally Trenholm <wa...@epochintegration.com>
Subject Re: URGENT: XML generation errors!!!
Date Sun, 27 Aug 2000 15:13:11 GMT
I wish I could help, but as Edwin Goei <Edwin.Goei@eng.sun.com> also
noticed, the line numbering in your include is not the same as in the file
that you compiled.  Can you indicate what specific line the VM is calling
39 ( from the stacktrace )?

FYI)

InvocationTargetException is what is thrown by methods that are called
using the reflection classes.  If this doesn't mean a lot to you,
don't worry about it; it is just a wrapper for the real exception
which is also listed in your stacktrace.

IllegalAccessException is caused when trying to load a class that is
not public or in the same package as the class that is currently
executing.

---

The only methods that you are calling from your class are things like
appendChild and createElement, which should not have access problems.

A couple of notes:

1-I know that ProjectX uses XmlDocument as the implementation of the
interface from org.w3c.dom.Document, and I am assuming that
ElementNode is just the ProjectX implementation of the
org.w3c.org.Element interface.

For simple tree manipulation ( or whereever possible ), you should try
to access these objects through the org.w3c.dom interfaces; it is more
portible for when you switch parsers.

EXAMPLE: 

instead of:
     XmlDocument xmlDoc = new XmlDocument();
 
     ElementNode tickets = (ElementNode)xmlDoc.createElement("TICKETS");

use:

public foo() {
	Document document = createDocument();
	org.w3c.dom.Element tickets = document.createElement( "TICKETS" );
}

// getting a new document cannot be done through the org.w3c.dom interfaces 
// so, why not wrap it in a method so you only have to change one line when you change parsers
private Document createDocument() {
	return( new XmlDocument() );
}




2-try a different parser; Xerces is a good one.  Even though you are
calling from the implementation classnames, you should not be seeing
an IllegalAccessException from what you are doing.  

Xerces is my parser choice for a number of reasons, and it is
open-source, which can be really helpful in situations like this.  I
don't know if ProjectX has source available, but if it did, and you
were DESPERATE, you could just declare the class in question public to
work around the IllegalAccessException ( no spam please ) and come
back to it once you had a real solution.





3-try a different VM.  I am not used to seeing uncaught exceptions
wrapped in a InnvocationTargetException.  It should not make a
difference, but whatever.




Other than that, the code seems to have the right idea.  Good luck,
you are on the right track.  It seems that you just got caught by a
rare snag; I am SURE that you will find a way through it.

_________________________________________________________________________
Wally Trenholm 		                           Epoch Integration Inc.
wally@epochintegration.com - Tel/Page: (416) 677 6744 Fax: (416) 677 6745
PGP-Fingerprint -------- FC DF D0 0C B4 DF E0 DC  73 AB 2A C4 A9 AB 0A 79

On Fri, 25 Aug 2000, Cheun N Chong wrote:

> 
> Dear all,
> 
> 	I have written the follwing codes, under JBuilder 3, and using
> library Java API for XML downloaded from Suns to generate
> an XML document:
> 
> =======================================================================
> import java.io.*;
> import org.w3c.dom.*;
> import com.sun.xml.tree.*;
> 
> public class XMLTicketGenerator {
> 
>   public static void main(String[] argv)
>      throws IOException, DOMException {
> 
>     XmlDocument xmlDoc = new XmlDocument();
> 
>     ElementNode tickets = (ElementNode)xmlDoc.createElement("TICKETS");
>     ElementNode owner = (ElementNode)xmlDoc.createElement("OWNER");
>     ElementNode ticket = (ElementNode)xmlDoc.createElement("TICKET");
>     ElementNode issuer = (ElementNode)xmlDoc.createElement("ISSUER");
>     ElementNode gameno = (ElementNode)xmlDoc.createElement("GAMENO");
>     ElementNode no = (ElementNode)xmlDoc.createElement("NO");
> 
>     xmlDoc.appendChild(tickets);            // The root <TICKETS>
> 
>     // The contents of the <TICKETS>
>     tickets.appendChild(ticket);
>     ticket.appendChild(owner);
>     ticket.appendChild(issuer);
>     ticket.appendChild(gameno);
>     ticket.appendChild(no);
> 
>     // Put in the element values into the tags
>     owner.appendChild(xmlDoc.createTextNode("12345678"));
>     issuer.appendChild(xmlDoc.createTextNode("98213412"));
>     gameno.appendChild(xmlDoc.createTextNode("3"));
>     no.appendChild(xmlDoc.createTextNode("4"));
> 
>     xmlDoc.write(new FileOutputStream("ticket.xml"));
>     System.exit(0);
>     
>   }
> }
> =========================================================================
> 
> 	The compilation is no problem. However when I tried to run this
> program the following error comes out:
> 
> AppAccelerator(tm) 1.2.010 for Java (JDK 1.2), x86 version
> Copyright (c) 1997-1999 Inprise Corporation. All Rights Reserved.
> java.lang.reflect.InvocationTargetException: java.lang.IllegalAccessError: try
> to access class com/sun/xml/tree/ParentNode from class XMLTicketGenerator
>  	at XMLTicketGenerator.main(XMLTicketGenerator.java:39)
>     	at java.lang.reflect.Method.invoke(Native method)
> 	at com.borland.jbuilder.util.BootStrap.invokeMain(Unknown Source)
> 	at com.borland.jbuilder.util.BootStrap.main(Unknown Source)
> 
> 	I referred to book Professional Java Server Programming from Wrox
> Press Ltd. pp 299. PLEASE HELP ME. I have been struggling this problem for
> ages and now becoming much desperate.
> 
> 	Thousand thanks for your expertise.
> 	
> 	
> 
> Best regards,
> Cheun Ngen CHONG
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> In case of troubles, e-mail:     webmaster@xml.apache.org
> To unsubscribe, e-mail:          general-unsubscribe@xml.apache.org
> For additional commands, e-mail: general-help@xml.apache.org
> 
> 





Mime
View raw message