Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Null Pointer Exception in ClusterRenderer When Continuously Updating Cluster Item Values #622

Open
mohammad-firmansyah opened this issue Sep 2, 2024 · 0 comments · May be fixed by #623
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@mohammad-firmansyah
Copy link

mohammad-firmansyah commented Sep 2, 2024

Environment details

  1. Android API 30
  2. kotlin 1.8.10
  3. maps compose 5.0.4
  4. agp 8.4
  5. compose 1.9.1

Steps to Reproduce

  1. Start with a mutable state list that is provided to the clustering composable.
  2. Continuously update the list within a while loop.
  3. Observe that the cluster changes its position as the list updates.
  4. Zoom in on the cluster until individual items are visible.
  5. Notice that a null pointer exception occurs during this process.

Related Codes

val list = remember {
          mutableStateOf(
              mutableListOf(Vehicle(
                  lat = 0.5,
                  lng = 0.5
              ),Vehicle(
                  lat = 0.8,
                  lng = 0.8
              ),Vehicle(
                  lat = 1.5,
                  lng = 1.5
              ),Vehicle(
                  lat = 0.6,
                  lng = 0.6
              ),Vehicle(
                  lat = 0.7,
                  lng = 0.5
              ),Vehicle(
                  lat = 0.10,
                  lng = 0.17
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.63,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.656,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.6116,
                  lng = 0.94
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.94
              ),Vehicle(
                  lat = 0.621,
                  lng = 0.912
              ),Vehicle(
                  lat = 0.62,
                  lng = 0.91
              ),Vehicle(
                  lat = 0.61,
                  lng = 0.39
              ))
          )
      }

Clustering(items = list,
                    onClusterClick = {
                        scope.launch {
                            cameraPositionState.animate(
                                CameraUpdateFactory.newLatLngZoom(it.position,20f)
                            )
                        }
                       false
                   }, clusterItemContent = {
                        InfoWindow(asset = it)
                   })
                   )
 LaunchedEffect(key1 = Unit) {
        while (true){
            list.value.first().lat = list.value.first().lat?.plus(0.1)
            delay(100)
        }
    }

Stack trace

java.lang.NullPointerException: null cannot be cast to non-null type android.view.ViewGroup
    at com.google.maps.android.compose.clustering.ComposeUiClusterRenderer.renderViewToBitmapDescriptor(ClusterRenderer.kt:175)
    at com.google.maps.android.compose.clustering.ComposeUiClusterRenderer.onBeforeClusterItemRendered(ClusterRenderer.kt:167)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.perform(DefaultClusterRenderer.java:1060)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$CreateMarkerTask.access$1900(DefaultClusterRenderer.java:1027)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.performNextTask(DefaultClusterRenderer.java:740)
    at com.google.maps.android.clustering.view.DefaultClusterRenderer$MarkerModifier.handleMessage(DefaultClusterRenderer.java:710)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:225)
    at android.app.ActivityThread.main(ActivityThread.java:7563)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:994)

@mohammad-firmansyah mohammad-firmansyah added triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage me I really want to be triaged. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
1 participant