AnsweredAssumed Answered

TypeError: Cannot read property 'sublayers' of null

Question asked by ocsurveygis on Jun 7, 2019
Latest reply on Jun 10, 2019 by LDanzinger-esristaff

I wrote a recursive function to read through our large  complicated service.  I get this error "TypeError: Cannot read property 'sublayers' of null".  It will error out at the same place every time, until I add a piece of code anywhere in the program then it will stop somewhere else or go through all the way.  It is predictably unpredictable. 

 


onLoadStatusChanged: {


console.log(mapImageLayer.mapImageSublayers.count)
if(mapImageLayer.mapImageSublayers.count > 0){

for (var x = 0; x < mapImageLayer.mapImageSublayers.count; x++) {

console.log("x = " + x.toString())
console.log("Outside: " + mapImageLayer.mapImageSublayers.get(x).name)
if(mapImageLayer.mapImageSublayers.get(x).sublayers.count > 0){
iname(mapImageLayer.mapImageSublayers.get(x))

}

}


}

}

 

function iname(thislayer) {

for (var y =0; y < thislayer.sublayers.count; y++) {


console.log(thislayer.subLayerContents[y].name)
console.log(thislayer.subLayerContents[y].sublayerId)
console.log("y = " + y.toString())
console.log("count= " + thislayer.subLayerContents[y].sublayers.count)

if(thislayer.subLayerContents[y].sublayers.count > 0){

console.log(thislayer.subLayerContents[y].name)
thislayer.subLayerContents[y].visible=true

}else{

thislayer.subLayerContents[y].visible=false

}

if(thislayer.subLayerContents[y].sublayers.count > 0){
iname(thislayer.subLayerContents[y])
}

}

}

 

 

Console:
qml: 9
qml: x = 0

qml: Outside: Districts
qml: Community College
qml: 1
qml: y = 0
qml: count= 0
qml: Supervisorial
qml: 2
qml: y = 1
qml: count= 0
qml: Elementary School
qml: 3
qml: y = 2
qml: count= 0
qml: High School
qml: 4
qml: y = 3

qml: count= 0
qml: Unified School
qml: 5
qml: y = 4
qml: count= 0
qml: Voter Precincts
qml: 6
qml: y = 5
qml: count= 0
qml: x = 1
qml: Outside: OC Development Services
qml: GENERAL PLAN
qml: 8
qml: y = 0
qml: count= 0
qml: Zoning
qml: 9
qml: y = 1
qml: count= 0
ArcGIS.AppFramework.Player: Object: QObject(0x0) Text: "file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:704: TypeError: Cannot read property 'sublayers' of null"
file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:704: TypeError: Cannot read property 'sublayers' of null

Outcomes