Note that there are some explanatory texts on larger screens.

plurals
  1. POValues returning null when using getter
    text
    copied!<p>I'm trying to inderstand what I'm doing wrong here, but it realy doesn't make sense to me. I have a class calleld LatLongBean Here I'm trying to parse an XML feed.</p> <p>I have a method where I do all the logic. and I have some getters and setters.</p> <p>It seems like the setter is working, but the getters are not working.</p> <p>This is the LatLongBean:</p> <pre><code>public class LatLongBean { private String lat; private String lng; private String address; private String url = "http://maps.googleapis.com/maps/api/geocode/xml?address="; public void LatLongBean(String address, String lat, String lng) throws ParserConfigurationException, SAXException, IOException { this.address = address; this.lat = lat; this.lng = lng; DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new URL(url + address + "&amp;sensor=false").openStream()); doc.getDocumentElement().normalize(); NodeList nodes = doc.getElementsByTagName("location"); for (int i = 0; i &lt; nodes.getLength(); i++) { Node node = nodes.item(i); if (node.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element) node; lat = getValue("lat", element); lng = getValue("lng", element); } } } private static String getValue(String tag, Element element) { NodeList nodes = element.getElementsByTagName(tag).item(0).getChildNodes(); Node node = (Node) nodes.item(0); return node.getNodeValue(); } public String getLat() { System.out.println(lat); return lat; } public String getLng() { System.out.println(lng); return lng; } public void setAddress(String address) { this.address = address; } } </code></pre> <p>and this is what I do to use this class:</p> <pre><code>LatLongBean latLong1 = new LatLongBean(); latLong1.setAddress("Amsterdam"); latLong1.getLat(); latLong1.getLng(); </code></pre> <p>The getters are returning null!</p> <p>When I make the LatLongBean method not void and use is as a constructor it works like a charm:</p> <pre><code>LatLongBean latLong1 = new LatLongBean("Amsterdam"); latLong1.getLat(); latLong1.getLng(); </code></pre> <p>Could someone please help me?</p> <p>Thanx in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload