var map;
            ], function(
            ) {

    map = new Map("mapDiv", {
        center: [-123.8425, 45.4552],
        zoom: 16,
        basemap: "streets"

    var imageParameters = new ImageParameters();

    imageParameters.layerOption = ImageParameters.LAYER_OPTION_SHOW;
    imageParameters.layerIds = [4];
    imageParameters.transparent = true;

    var dynamicMapServiceLayer = new ArcGISDynamicMapServiceLayer("http://host:6080/arcgis/rest/services/Data/MapServer", {
          "opacity" : 1.0,
          "imageParameters": imageParameters


    queryTask = new QueryTask("http://host:6080/arcgis/rest/services/Data/MapServer/4");

    query = new Query();
    query.returnGeometry = true;
    query.outFields = ["OBJECTID"];

    infoTemplate = new InfoTemplate("${OBJECTID}", "OBJECTID : ${OBJECTID}");

    symbol = new SimpleMarkerSymbol();
    symbol.setColor(new Color([255,0,0,1]));

    query.where = "OBJECTID = 1";

    queryTask.execute(query, showResults);

    function showResults(featureSet) {
        //remove all graphics on the maps graphics layer

        //Performance enhancer - assign featureSet array to a single variable.
        var resultFeatures = featureSet.features;

        //Loop through each feature returned
        for (var i=0, il=resultFeatures.length; i<il; i++) {
            //Get the current feature from the featureSet.
            //Feature is a graphic
            var graphic = resultFeatures[i];

            //Set the infoTemplate.

            //Add graphic to the map graphics layer.


I followed this ESRI example:


But when I test it I get an error:

Resource interpreted as Script but transferred with MIME type text/plain: "http://host:6080/arcgis/rest/services/Data/MapServer/4/q…Fields=OBJECTID&callback=dojo.io.script.jsonp_dojoIoScript3._jsonpCallback". init.js:495
Resource interpreted as Script but transferred with MIME type text/plain: "http://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer?f=json&callback=dojo.io.script.jsonp_dojoIoScript1._jsonpCallback". init.js:495
TypeError {stack: (...), message: "Cannot read property 'clear' of null"}
 "TypeError: Cannot read property 'clear' of null
    at showResults (http://test/test/script.js:61:15)
    at e._successHandler (http://js.arcgis.com/3.10/init.js:490:193)
    at e._handler (http://js.arcgis.com/3.10/init.js:1424:385)
    at http://js.arcgis.com/3.10/init.js:174:23
    at Object.d.load (http://js.arcgis.com/3.10/init.js:1420:411)
    at http://js.arcgis.com/3.10/init.js:630:478
    at c (http://js.arcgis.com/3.10/init.js:74:221)
    at d (http://js.arcgis.com/3.10/init.js:74:10)
    at resolve.callback (http://js.arcgis.com/3.10/init.js:75:350)
    at c (http://js.arcgis.com/3.10/init.js:74:436)" 

I know there should be a query result because I tested it through REST. I entered the query OBJECTID = 1 through REST and it returned a single record.

Any idea what could be wrong? I'm stumped.

  • It would help if you could edit your question to remove the extraneous detail in your code sample, and create the smallest possible code which demonstrates the problem, as at jsfiddle.net/slead/m4GRV (eg the dynamic layer, info template, symbology etc are unrelated to this problem) Jul 25 '14 at 3:52
  • Is that better?
    – geogeogeo
    Jul 25 '14 at 4:07
  • when is the error thrown - is it definitely when you run QueryTask.execute? Can you step through in Firebug and verify that it's the query causing the error, and also check the Net tab to see exactly what's being sent to the server? Jul 25 '14 at 6:18

Your query is working fine. The error stack trace you've submitted is pointing to the part of your showResults function where the map's graphics layer is told to clear. The this is usually thrown because the map's graphics layer hasn't loaded, which is probably because the map hasn't finished loading yet.

Where you have:

query.where = "OBJECTID = 1";

queryTask.execute(query, showResults);

Try replacing with the following:

if (map.loaded) {
    query.where = "OBJECTID = 1";
    queryTask.execute(query, showResults);
} else {
    map.on("load", function () {
        query.where = "OBJECTID = 1";
        queryTask.execute(query, showResults);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.