Jump to content


Photo

Java, Sax Problem.


  • This topic is locked This topic is locked
1 reply to this topic

#1 U1

U1

    Young Padawan

  • Members
  • Pip
  • 245 posts

Posted 18 December 2007 - 09:58 AM

Alright im stilla newbie to java but anyways here's my prob, i use SAX to render a treeview table of contents from XML where the source look slike this:

<?xml version='1.0' encoding='ISO-8859-1' ?>
<toc version="1.0">
  <tocitem target="booktoca_htm_6017" text="Introduction">
	<tocitem target="booktoca_htm_6019" text="What is Transmitter
Reporter?"/>
	<tocitem target="booktoca_htm_6021" text="Finding the Report You
Need"/>
	<tocitem target="booktoca_htm_6023" text="Using Help"/>
  </tocitem>
</toc>

To handle tracking what level in the tree I'm at, I thought I'd use a stack
so my handler is as follows:
public class TOCHandler extends HandlerBase 
	{
		private java.util.Stack stack;
		
		public void startElement(String name, AttributeList atts)
		{
			System.out.println("Start element: " + name);
			
			if (name.equals("tocitem"))
			{
			  String text = atts.getValue("text");
			
			  if (stack.empty())
			  {
				symantec.itools.awt.TreeNode child = new
symantec.itools.awt.TreeNode(text, Contents);
				
				Contents.append(child);
				
				stack.push(child);
			  }
			  else
			  {
				symantec.itools.awt.TreeNode child = new
symantec.itools.awt.TreeNode(text, Contents);
				
				symantec.itools.awt.TreeNode parent =
(symantec.itools.awt.TreeNode) stack.peek();
				
				stack.push(child);
				
				Contents.addChild(child, parent);		
			  }
			}
		} 

		public void endElement(String name)
		{
			System.out.println("End element: " + name);
			
			if (name.equals("toc"))
			  Contents.redraw();
			  
			if (name.equals("tocitem"))
			  stack.pop();
		}
	}

I get a SAXException of type null when the first check to stack.empty() happens? Does it have something to do with the fact that the stack methods are declared synchronized?

Hope there some java lovers out there to help.

Cheers

Edited by itypeos, 18 December 2007 - 02:28 PM.


#2 U1

U1

    Young Padawan

  • Members
  • Pip
  • 245 posts

Posted 18 December 2007 - 02:26 PM

Never mind, found the problem :), stack wasn't initialized.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users