Help with loadData() please. +

I’m following along on the Coursera/UCSD class on Java programming. I realize this may be an Unfolding issue, but it seems that Unfolding and Processing are inextricably linked, so here I am.

I’m getting a null pointer exception when I try to convert a list of features into a list of markers using the method MapUtils.createSimpleMarkers().

The issue seems to be that GeoDataReader.loadData() is not populating the list of features. I can not tell why.

This code is copied and pasted straight from class. I’m less than happy with how outdated this course is, but I’d like to finish the assignments. Thank you.

countryMarkers = MapUtils.createSimpleMarkers(countries);

Here is the larger picture:

public class LifeExpectancy extends PApplet{
    UnfoldingMap map;
    private String year = "2017";
    private String csvPath = "data/LifeExpectancyWorldBank.csv";
    private String xmlPath = "data/life_expectancy.xml";
    private List<Feature> countries;
    private List<Marker> countryMarkers;
    private Map<String, Float> dataMap;
    
    
    public void setup(){
        countries = GeoDataReader.loadData(this, 
                "data/countries.geo.json");
        countryMarkers = MapUtils.createSimpleMarkers(countries);

        size(800,600, OPENGL);
        map = new UnfoldingMap(this, 50, 50, 700, 500,
                new Microsoft.RoadProvider());

        MapUtils.createDefaultEventDispatcher(this, map);
        
        try {
            dataMap = loadLifeExpectancyData();
        } catch (IOException ex) {
            System.err.println(ex.getMessage());
        }

        map.addMarkers(countryMarkers);
        shadeMarkers();
    }
    
    public void draw(){
        map.draw();
    }

As a side note, the JSON file is provided with the course. I’ve opened it up to confirm that it has data in it. I’m not an expert, but everything looks good.

2 Likes

I have tested the JSON file that came with the course at http://geojsonlint.com/ and it is invalid.

I replaced the file with one pulled from https://datahub.io/core/geo-countries#data that is valid, and the issue persists.

Poblem Solved: I was using the wrong reader: GeoDataReader. Should have used GeoJSONReader. My IDE must have auto corrected a typo, and I never noticed.

2 Likes