Bug in ArcGISFeatureLayer.getField(String fieldName)?

3686
1
10-03-2013 07:41 AM
JasonKnisley
Occasional Contributor
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?
0 Kudos
1 Reply
MengyiGuo
Occasional Contributor

I tested the code and seems it works on ArcGIS Runtime SDK for Android 10.2.5. I noticed it has been a while so I'm not sure if you still have the issue. Besides, it seems that your layer variable name is testLayer but when you log it, the layer variable name is featureLayer.

Please test the following code and let me know if it works:

final ArcGISFeatureLayer testLayer = new ArcGISFeatureLayer("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/Petroleum/KSFields/FeatureServer/0", ArcGISFeatureLayer.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, testLayer.getName() + ": found " + fields.length + " fields");

                    boolean found = false;

                    for (Field field : fields) {

                        if (testLayer.getField(field.getName()) != null) {

                            Log.d(TAG, testLayer.getName() + ": found field object for " + field.getName());

                            found = true;

                        }

                    }

                    if (!found) {

                        Log.d(TAG, testLayer.getName() + ": no field objects found by name");

                    }

                }

            }

        });

I got the following outputs:

02-19 11:35:51.207    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found 23 fields

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for objectid

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for field_kid

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for approxacre

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for field_name

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for status

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for prod_gas

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for prod_oil

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for activeprod

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for cumm_oil

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for maxoilwell

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastoilpro

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastoilwel

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastodate

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for cumm_gas

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for maxgaswell

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastgaspro

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastgaswel

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for lastgdate

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for avgdepth

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for avgdepthsl

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for polydate

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for field_type

02-19 11:35:51.208    6837-6837/com.arcgis.android.samples.maps.helloworld D/Test!!﹕ Current Kansas Field Production: found field object for field_kidn

0 Kudos