knisleyj

Bug in ArcGISFeatureLayer.getField(String fieldName)?

Discussion created by knisleyj on Oct 3, 2013
Latest reply on Feb 19, 2015 by MGuo-esristaff
I was writing a program where I needed to check properties of various fields, and so I decided to use the ArcGISFeatureLayer.getField(String fieldName) but kept experiencing errors. The return value was always null. So as a quick test, I did this...


final ArcGISFeatureLayer testLayer = new ArcGISFeatureLayer(
    "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0",
    MODE.SNAPSHOT);
        
testLayer.setOnStatusChangedListener(new OnStatusChangedListener() {
    private static final long serialVersionUID = 1L;

    public void onStatusChanged(Object arg0, STATUS arg1) {
        if (arg1 == STATUS.INITIALIZED) {
            Field[] fields = testLayer.getFields();
            Log.d(TAG, featureLayer.getName() + ": found " + fields.length + " fields");
            boolean found = false;
            for (Field field : fields) {
                if (testLayer.getField(field.getName()) != null) {
                    Log.d(TAG, featureLayer.getName() + ": found field object for " + field.getName());
                    found = true;
                }
            }
            if (!found) {
                Log.d(TAG, featureLayer.getName() + ": no field objects found by name");
            }
        }
    }
});


Which results in
!! Current Kansas Field Production: found 23 fields
!! Current Kansas Field Production: no field object found by name


Why does getField(fieldName) always return null?

Outcomes