<?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 Exception when trying to get targetGeometry from a viewpoint in ArcGIS Runtime SDK for Android Questions</title>
    <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/exception-when-trying-to-get-targetgeometry-from-a/m-p/1058981#M5496</link>
    <description>&lt;P&gt;I am getting a crash trying to get the&amp;nbsp;&lt;STRONG&gt;targetGeometry&lt;/STRONG&gt; inside the body of a&amp;nbsp;&lt;STRONG&gt;addViewpointChangedListener.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The crash happens inconsistently but often, looks like a race condition when the map has just been created and the first viewpoint update is somehow not ready to provide the current viewpoint.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reproduced using&amp;nbsp;arcgis-android version 100.10.0 and&amp;nbsp;100.11.0 but not&amp;nbsp;100.6.0.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To reproduce add the viewpoint changed listener to the default 'present map' sample project and try to restart the app a few times:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;ArcGISRuntimeEnvironment.setApiKey("YOUR_API_KEY")

val map = ArcGISMap(BasemapStyle.ARCGIS_NAVIGATION)

mapView.map = map

mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 72000.0))

mapView.addViewpointChangedListener { event -&amp;gt;
            
   event.source.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE)?.let { 
      viewpoint -&amp;gt;
      (viewpoint.targetGeometry as? Point)?.let {
         Log.d(TAG, "viewpoint update. Location: ${(GeometryEngine.project(it, SpatialReferences.getWgs84()) as Point)}")
      }
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stacktrace of the exception:&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;E/AndroidRuntime: FATAL EXCEPTION: main
    Process: me.oriient.arcgisplayground, PID: 14075
    com.esri.arcgisruntime.ArcGISRuntimeException: Nullability violation: ArcGIS Runtime: 1
    Null pointer.
    object cannot be null.
        at com.esri.arcgisruntime.internal.jni.CoreViewpoint.nativeGetTargetGeometry(Native Method)
        at com.esri.arcgisruntime.internal.jni.CoreViewpoint.f(SourceFile:1)
        at com.esri.arcgisruntime.mapping.Viewpoint.getTargetGeometry(SourceFile:2)
        at me.oriient.arcgisplayground.MainActivity$setupMap$1.viewpointChanged(MainActivity.kt:39)
        at com.esri.arcgisruntime.a.i.f.j0$a.run(SourceFile:1)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6986)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 May 2021 15:23:21 GMT</pubDate>
    <dc:creator>MichaelKrutoyarskiy</dc:creator>
    <dc:date>2021-05-18T15:23:21Z</dc:date>
    <item>
      <title>Exception when trying to get targetGeometry from a viewpoint</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/exception-when-trying-to-get-targetgeometry-from-a/m-p/1058981#M5496</link>
      <description>&lt;P&gt;I am getting a crash trying to get the&amp;nbsp;&lt;STRONG&gt;targetGeometry&lt;/STRONG&gt; inside the body of a&amp;nbsp;&lt;STRONG&gt;addViewpointChangedListener.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The crash happens inconsistently but often, looks like a race condition when the map has just been created and the first viewpoint update is somehow not ready to provide the current viewpoint.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Reproduced using&amp;nbsp;arcgis-android version 100.10.0 and&amp;nbsp;100.11.0 but not&amp;nbsp;100.6.0.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;To reproduce add the viewpoint changed listener to the default 'present map' sample project and try to restart the app a few times:&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;ArcGISRuntimeEnvironment.setApiKey("YOUR_API_KEY")

val map = ArcGISMap(BasemapStyle.ARCGIS_NAVIGATION)

mapView.map = map

mapView.setViewpoint(Viewpoint(34.0270, -118.8050, 72000.0))

mapView.addViewpointChangedListener { event -&amp;gt;
            
   event.source.getCurrentViewpoint(Viewpoint.Type.CENTER_AND_SCALE)?.let { 
      viewpoint -&amp;gt;
      (viewpoint.targetGeometry as? Point)?.let {
         Log.d(TAG, "viewpoint update. Location: ${(GeometryEngine.project(it, SpatialReferences.getWgs84()) as Point)}")
      }
   }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stacktrace of the exception:&lt;/P&gt;&lt;LI-CODE lang="markdown"&gt;E/AndroidRuntime: FATAL EXCEPTION: main
    Process: me.oriient.arcgisplayground, PID: 14075
    com.esri.arcgisruntime.ArcGISRuntimeException: Nullability violation: ArcGIS Runtime: 1
    Null pointer.
    object cannot be null.
        at com.esri.arcgisruntime.internal.jni.CoreViewpoint.nativeGetTargetGeometry(Native Method)
        at com.esri.arcgisruntime.internal.jni.CoreViewpoint.f(SourceFile:1)
        at com.esri.arcgisruntime.mapping.Viewpoint.getTargetGeometry(SourceFile:2)
        at me.oriient.arcgisplayground.MainActivity$setupMap$1.viewpointChanged(MainActivity.kt:39)
        at com.esri.arcgisruntime.a.i.f.j0$a.run(SourceFile:1)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6986)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 May 2021 15:23:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/exception-when-trying-to-get-targetgeometry-from-a/m-p/1058981#M5496</guid>
      <dc:creator>MichaelKrutoyarskiy</dc:creator>
      <dc:date>2021-05-18T15:23:21Z</dc:date>
    </item>
    <item>
      <title>Re: Exception when trying to get targetGeometry from a viewpoint</title>
      <link>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/exception-when-trying-to-get-targetgeometry-from-a/m-p/1060910#M5501</link>
      <description>&lt;P&gt;I've found a way to validate if the viewpoint is ready to be processed.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="kotlin"&gt;if (viewpoint.type == com.esri.arcgisruntime.mapping.Viewpoint.Type.UNKNOWN) {
   return
}&lt;/LI-CODE&gt;&lt;P&gt;Using this simple check we can ignore the viewpoints which will cause a crash another way.&lt;/P&gt;</description>
      <pubDate>Mon, 24 May 2021 12:34:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-runtime-sdk-for-android-questions/exception-when-trying-to-get-targetgeometry-from-a/m-p/1060910#M5501</guid>
      <dc:creator>MichaelKrutoyarskiy</dc:creator>
      <dc:date>2021-05-24T12:34:01Z</dc:date>
    </item>
  </channel>
</rss>

