Question

I want to show a list of points (lat and longs) using GMapLatLng. But when I run the project it gives a null pointer exception in "latlngList.add(l3); " line. what is the reason for that, and what should I do to over come?

Backing bean

public class ManagedBean {
    private String name;
    private String greeting = "Greetings";
    private String lat;
    private String lon;
    private List<GMapLatLng> latlngList;
    private GMapLatLngs lats;

    public ManagedBean(){       
        GMapLatLng l1 = new GMapLatLng("6.911878", "79.855134");
        GMapLatLng l2 = new GMapLatLng("6.911963", "79.854705");
        GMapLatLng l3 = new GMapLatLng("6.911974", "79.853847");

        latlngList.add(l3);
        latlngList.add(l2);
        latlngList.add(l1);
    }


    public GMapLatLngs getLats() {
        return lats;
    }
    public void setLats(GMapLatLngs lats) {
        this.lats = lats;
    }
    public List<GMapLatLng> getLatlngList() {
        return latlngList;
    }
    public void setLatlngList(List<GMapLatLng> latlngList) {
        this.latlngList = latlngList;
    }
    public String getLat() {
        return lat;
    }
    public void setLat(String lat) {
        this.lat = lat;
    }
    public String getLon() {
        return lon;
    }
    public void setLon(String lon) { 
        this.lon = lon;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getGreeting() {
        return greeting;
    }
    public void setGreeting(String greeting) {
        this.greeting = greeting;
    }

    public void sayHello(ActionEvent event){
        System.out.println("Fired...");
        this.greeting = "Hellooo, "+name;
        /*this.lat = "6.911580";
        this.lon = "79.849620";*/

    }
   }

icefaces.xhtml

   <ice:form>             
             <ice:gMap zoomLevel="17" latitude="6.911580" longitude="79.849620">
              <ice:gMapMarker>
                <ice:gMapLatLngs value="#{managedBean.latlngList}"></ice:gMapLatLngs>   
              </ice:gMapMarker>
             </ice:gMap>          
   </ice:form>
Was it helpful?

Solution

latlngList is null. Initialize it with new ArrayList() before adding stuff into it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top