Reply from StrayChild on Apr 18 at 4:42 PM Sorry, I forgot to add this inside accept(): System.out.println(getMap().size());
| | | ---------------Original Message--------------- From: StrayChild Sent: Wednesday, April 18, 2012 4:37 PM Subject: Scope of a Variable in Java Hi, I'm having a trouble with this: It seems that somehow I'm not accessing correctly the myMap member of the class: public class MyClass implements javax.xml.stream.StreamFilter() { private Map myMap= new HashMap(); public Map getMap() { return this.myMap; } public void addElement(String text) { this.myMap.add(text); } public static void main() { XMLInputFactory xmlif = null; xmlif = XMLInputFactory.newInstance(); FileInputStream fis = new FileInputStream("myFile.xml"); XMLStreamReader xmlr = xmlif.createFilteredReader(xmlif.createXMLStreamRe ader(fis),new MyClass()); addElement("Something") } public void accept() { if ( getMap().containsKey("Something") ) { System.out.println("The value is there"); } } } When I try to do this, it says that the size is 0.
| | Reply to this email to post your response. __.____._ | In the Spotlight Become a blogger at Toolbox.com and share your expertise with the community. Start today. _.____.__ |
No comments:
Post a Comment