Skip to content

Conversation

@m1ga
Copy link
Contributor

@m1ga m1ga commented Oct 7, 2023

I was searching the code what could cause this error

java.lang.NullPointerException: Attempt to invoke virtual method 'int com.google.android.gms.maps.model.LatLng.hashCode()' on a null object reference
       at com.google.maps.android.clustering.algo.StaticCluster.hashCode(StaticCluster.java:71)
       at java.util.HashMap.hash(HashMap.java:336)
       at java.util.HashMap.put(HashMap.java:608)
       at java.util.HashSet.add(HashSet.java:220)
       at com.google.maps.android.clustering.algo.NonHierarchicalDistanceBasedAlgorithm.getClusters(NonHierarchicalDistanceBasedAlgorithm.java:201)
       at com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.getClustersInternal(PreCachingAlgorithmDecorator.java:141)
       at com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator.access$000(PreCachingAlgorithmDecorator.java:34)
       at com.google.maps.android.clustering.algo.PreCachingAlgorithmDecorator$PrecacheRunnable.run(PreCachingAlgorithmDecorator.java:164)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:644)
       at java.lang.Thread.run(Thread.java:1012)

and I found one place in our ClusterRenderer in getPositiom() that could return null for a cluster. BUT with Android Studio I saw that it actually is marked as @NonNull. So I've added that in our override and in rare cases where it was returning null before (when the proxy is gone already but it still tries to create a cluster) it now returns LatLng(0,0). From my understanding that should only be the case when you e.g. close a window and it is clustering items and they are being removed.

Also added another null check for tiMarker before adding a cluster item.

I've tested it with annotations at position 0,0 and they are displayed and also clustered. So in a rare case when you want to add something at 0,0 it still is displayed 😄

I couldn't verify if this fixes that error because it happens very very rarely. But using this for a couple of days now and no crash so far 🤞

ti.map-android-5.6.2.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants