Hello, I'm trying to parse through XML and while I'm able to parse it, it will not add the final object to the arraylist. The if statement is still accessed though as I've tested it with println's, so the issue is pinpointed to the object not being able to be added to the arraylist. Any help with this would be much appreciated! Thanks in advance!
import java.awt.List; import java.io.*; import java.util.ArrayList; import java.util.Iterator; import org.xml.sax.*; import org.xml.sax.helpers.*; public class SimpleSAXParser3 extends DefaultHandler { ArrayList<CustomOverlay> customOverlays = new ArrayList<CustomOverlay>(); boolean registry = false; boolean businessBool = false; boolean longBool = false; boolean streetBool = false; String businessName = null; String longitude = null; String street1 = null; public void startElement(String nsURI, String strippedName, String tagName, Attributes attributes) throws SAXException { //move down the tree if (tagName.equalsIgnoreCase("business-name")) { businessBool = true; // System.out.println("tag found"); } else if (tagName.equalsIgnoreCase("longitude")) { longBool = true; // System.out.println("tag found"); } else if (tagName.equalsIgnoreCase("street1")) { streetBool = true; } //} } public void characters(char[] ch, int start, int length) { if (businessBool) { System.out.println(new String(ch,start,length)); businessName = new String(ch, start, length); businessBool = false; } else if (longBool) { System.out.println(new String(ch,start,length)); longitude = new String(ch, start,length); longBool = false; } else if (streetBool) { System.out.println(new String(ch,start,length)); street1 = new String(ch,start,length); streetBool = false; } // addElement(); [B]// the following if statement is accessed[/B] if ((businessName != null) && (longitude != null) && (street1 != null)) { addElement(); //is properly run } } public void addElement () { //neither of these is added according to my toString1() method customOverlays.add(new CustomOverlay(businessName,longitude,street1)); customOverlays.add(new CustomOverlay("string","String","String")); businessName = null; longitude = null; street1 = null; } public void toString1() { if (customOverlays.size() > 0) { System.out.print("somethings in there"); } else System.out.print("nothings there"); } public void list() throws Exception { XMLReader parser = XMLReaderFactory.createXMLReader(); parser.setContentHandler(new SimpleSAXParser3()); parser.parse("RegistryXML.xml"); } //fixed main, problem still exists public static void main(String[] args) throws Exception { SimpleSAXParser3 simp = new SimpleSAXParser3(); simp.list(); simp.toString1(); } }