<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic TypeError: Cannot read property 'sublayers' of null in Qt Maps SDK Questions</title>
    <link>https://community.esri.com/t5/qt-maps-sdk-questions/typeerror-cannot-read-property-sublayers-of-null/m-p/55937#M279</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote a recursive function to read through our large&amp;nbsp; complicated service.&amp;nbsp; I get&amp;nbsp;this error "TypeError: Cannot read property 'sublayers' of null".&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;It is predictably unpredictable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;onLoadStatusChanged: {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; console.log(mapImageLayer.mapImageSublayers.count)&lt;BR /&gt; if(mapImageLayer.mapImageSublayers.count &amp;gt; 0){&lt;/P&gt;&lt;P&gt;for (var x = 0; x &amp;lt; mapImageLayer.mapImageSublayers.count; x++) {&lt;/P&gt;&lt;P&gt;console.log("x = " + x.toString())&lt;BR /&gt; console.log("Outside: " + mapImageLayer.mapImageSublayers.get(x).name)&lt;BR /&gt; if(mapImageLayer.mapImageSublayers.get(x).sublayers.count &amp;gt; 0){&lt;BR /&gt; iname(mapImageLayer.mapImageSublayers.get(x))&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function iname(thislayer) {&lt;/P&gt;&lt;P&gt;for (var y =0; y &amp;lt; thislayer.sublayers.count; y++) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; console.log(thislayer.subLayerContents&lt;Y&gt;.name)&lt;BR /&gt; console.log(thislayer.subLayerContents&lt;Y&gt;.sublayerId)&lt;BR /&gt; console.log("y = " + y.toString())&lt;BR /&gt; console.log("count= " + thislayer.subLayerContents&lt;Y&gt;.sublayers.count)&lt;/Y&gt;&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;if(thislayer.subLayerContents&lt;Y&gt;.sublayers.count &amp;gt; 0){&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;console.log(thislayer.subLayerContents&lt;Y&gt;.name)&lt;BR /&gt; thislayer.subLayerContents&lt;Y&gt;.visible=true&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}else{&lt;/P&gt;&lt;P&gt;thislayer.subLayerContents&lt;Y&gt;.visible=false&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if(thislayer.subLayerContents&lt;Y&gt;.sublayers.count &amp;gt; 0){&lt;BR /&gt; iname(thislayer.subLayerContents&lt;Y&gt;)&lt;BR /&gt; }&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Console:&lt;BR /&gt;qml: 9&lt;BR /&gt;qml: x = 0&lt;/P&gt;&lt;P&gt;qml: Outside: Districts&lt;BR /&gt;qml: Community College&lt;BR /&gt;qml: 1&lt;BR /&gt;qml: y = 0&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Supervisorial&lt;BR /&gt;qml: 2&lt;BR /&gt;qml: y = 1&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Elementary School&lt;BR /&gt;qml: 3&lt;BR /&gt;qml: y = 2&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: High School&lt;BR /&gt;qml: 4&lt;BR /&gt;qml: y = 3&lt;/P&gt;&lt;P&gt;qml: count= 0&lt;BR /&gt;qml: Unified School&lt;BR /&gt;qml: 5&lt;BR /&gt;qml: y = 4&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Voter Precincts&lt;BR /&gt;qml: 6&lt;BR /&gt;qml: y = 5&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: x = 1&lt;BR /&gt;qml: Outside: OC Development Services&lt;BR /&gt;qml: GENERAL PLAN&lt;BR /&gt;qml: 8&lt;BR /&gt;qml: y = 0&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Zoning&lt;BR /&gt;qml: 9&lt;BR /&gt;qml: y = 1&lt;BR /&gt;qml: count= 0&lt;BR /&gt;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"&lt;BR /&gt;file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:704: TypeError: Cannot read property 'sublayers' of null&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 07 Jun 2019 18:10:02 GMT</pubDate>
    <dc:creator>JosephHunt</dc:creator>
    <dc:date>2019-06-07T18:10:02Z</dc:date>
    <item>
      <title>TypeError: Cannot read property 'sublayers' of null</title>
      <link>https://community.esri.com/t5/qt-maps-sdk-questions/typeerror-cannot-read-property-sublayers-of-null/m-p/55937#M279</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote a recursive function to read through our large&amp;nbsp; complicated service.&amp;nbsp; I get&amp;nbsp;this error "TypeError: Cannot read property 'sublayers' of null".&amp;nbsp; 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.&amp;nbsp;&amp;nbsp;It is predictably unpredictable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;onLoadStatusChanged: {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; console.log(mapImageLayer.mapImageSublayers.count)&lt;BR /&gt; if(mapImageLayer.mapImageSublayers.count &amp;gt; 0){&lt;/P&gt;&lt;P&gt;for (var x = 0; x &amp;lt; mapImageLayer.mapImageSublayers.count; x++) {&lt;/P&gt;&lt;P&gt;console.log("x = " + x.toString())&lt;BR /&gt; console.log("Outside: " + mapImageLayer.mapImageSublayers.get(x).name)&lt;BR /&gt; if(mapImageLayer.mapImageSublayers.get(x).sublayers.count &amp;gt; 0){&lt;BR /&gt; iname(mapImageLayer.mapImageSublayers.get(x))&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; }&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function iname(thislayer) {&lt;/P&gt;&lt;P&gt;for (var y =0; y &amp;lt; thislayer.sublayers.count; y++) {&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; console.log(thislayer.subLayerContents&lt;Y&gt;.name)&lt;BR /&gt; console.log(thislayer.subLayerContents&lt;Y&gt;.sublayerId)&lt;BR /&gt; console.log("y = " + y.toString())&lt;BR /&gt; console.log("count= " + thislayer.subLayerContents&lt;Y&gt;.sublayers.count)&lt;/Y&gt;&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;if(thislayer.subLayerContents&lt;Y&gt;.sublayers.count &amp;gt; 0){&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;console.log(thislayer.subLayerContents&lt;Y&gt;.name)&lt;BR /&gt; thislayer.subLayerContents&lt;Y&gt;.visible=true&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}else{&lt;/P&gt;&lt;P&gt;thislayer.subLayerContents&lt;Y&gt;.visible=false&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;if(thislayer.subLayerContents&lt;Y&gt;.sublayers.count &amp;gt; 0){&lt;BR /&gt; iname(thislayer.subLayerContents&lt;Y&gt;)&lt;BR /&gt; }&lt;/Y&gt;&lt;/Y&gt;&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Console:&lt;BR /&gt;qml: 9&lt;BR /&gt;qml: x = 0&lt;/P&gt;&lt;P&gt;qml: Outside: Districts&lt;BR /&gt;qml: Community College&lt;BR /&gt;qml: 1&lt;BR /&gt;qml: y = 0&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Supervisorial&lt;BR /&gt;qml: 2&lt;BR /&gt;qml: y = 1&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Elementary School&lt;BR /&gt;qml: 3&lt;BR /&gt;qml: y = 2&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: High School&lt;BR /&gt;qml: 4&lt;BR /&gt;qml: y = 3&lt;/P&gt;&lt;P&gt;qml: count= 0&lt;BR /&gt;qml: Unified School&lt;BR /&gt;qml: 5&lt;BR /&gt;qml: y = 4&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Voter Precincts&lt;BR /&gt;qml: 6&lt;BR /&gt;qml: y = 5&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: x = 1&lt;BR /&gt;qml: Outside: OC Development Services&lt;BR /&gt;qml: GENERAL PLAN&lt;BR /&gt;qml: 8&lt;BR /&gt;qml: y = 0&lt;BR /&gt;qml: count= 0&lt;BR /&gt;qml: Zoning&lt;BR /&gt;qml: 9&lt;BR /&gt;qml: y = 1&lt;BR /&gt;qml: count= 0&lt;BR /&gt;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"&lt;BR /&gt;file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:704: TypeError: Cannot read property 'sublayers' of null&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Jun 2019 18:10:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/qt-maps-sdk-questions/typeerror-cannot-read-property-sublayers-of-null/m-p/55937#M279</guid>
      <dc:creator>JosephHunt</dc:creator>
      <dc:date>2019-06-07T18:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: TypeError: Cannot read property 'sublayers' of null</title>
      <link>https://community.esri.com/t5/qt-maps-sdk-questions/typeerror-cannot-read-property-sublayers-of-null/m-p/55938#M280</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Seems most likely like a timing issue. Have you made sure that all of the loadable classes are loaded? For example, the map image layer needs to be in state loadStatus === Enums.LoadStatusLoaded. And each sublayer needs to be loaded before accessing sublayers. More details here -&amp;nbsp;&lt;A href="https://developers.arcgis.com/qt/latest/qml/guide/loadable-pattern.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;https://developers.arcgis.com/qt/latest/qml/guide/loadable-pattern.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for example, you could do something like&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;sublayer.loadStatusChanged.connect(function(){ 
  if (sublayer.loadStatus === Enums.LoadStatusLoaded) {
    // access the sublayers now
  }
});&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:07:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/qt-maps-sdk-questions/typeerror-cannot-read-property-sublayers-of-null/m-p/55938#M280</guid>
      <dc:creator>LucasDanzinger</dc:creator>
      <dc:date>2021-12-10T22:07:46Z</dc:date>
    </item>
  </channel>
</rss>

