{"record":{"id":"392cae574e4ff221","repo":"microg/GmsCore","slug":"cameraupdatefactory-is-not-initialized","errorCode":null,"errorMessage":"CameraUpdateFactory is not initialized","messagePattern":"CameraUpdateFactory is not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"play-services-maps/src/main/java/com/google/android/gms/maps/CameraUpdateFactory.java","lineNumber":29,"sourceCode":"import android.os.RemoteException;\nimport androidx.annotation.NonNull;\nimport com.google.android.gms.maps.internal.ICameraUpdateFactoryDelegate;\nimport com.google.android.gms.maps.model.CameraPosition;\nimport org.microg.gms.common.Hide;\n\n/**\n * A class containing methods for creating {@link CameraUpdate} objects that change a map's camera. To modify the map's camera, call\n * {@link GoogleMap#animateCamera(CameraUpdate)}, {@link GoogleMap#animateCamera(CameraUpdate, GoogleMap.CancelableCallback)} or\n * {@link GoogleMap#moveCamera(CameraUpdate)}, using a {@link CameraUpdate} object created with this class.\n */\npublic class CameraUpdateFactory {\n    private static ICameraUpdateFactoryDelegate delegate;\n    @Hide\n    public static void setDelegate(@NonNull ICameraUpdateFactoryDelegate delegate) {\n        CameraUpdateFactory.delegate = delegate;\n    }\n    private static ICameraUpdateFactoryDelegate getDelegate() {\n        if (delegate == null) throw new IllegalStateException(\"CameraUpdateFactory is not initialized\");\n        return delegate;\n    }\n\n    /**\n     * Returns a {@link CameraUpdate} that moves the camera to a specified {@link CameraPosition}. In effect, this creates a transformation from the\n     * {@link CameraPosition} object's latitude, longitude, zoom level, bearing and tilt.\n     *\n     * @param cameraPosition The requested position. Must not be {@code null}.\n     * @return a {@link CameraUpdate} containing the transformation.\n     */\n    public static CameraUpdate newCameraPosition(@NonNull CameraPosition cameraPosition) {\n        try {\n            return new CameraUpdate(getDelegate().newCameraPosition(cameraPosition));\n        } catch (RemoteException e) {\n            throw new RuntimeException(e);\n        }\n    }\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/microg/GmsCore/blob/157c9d86ac46c195a86c2f15ab55c84036223f95/play-services-maps/src/main/java/com/google/android/gms/maps/CameraUpdateFactory.java#L11-L47","documentation":"CameraUpdateFactory delegates all camera-update creation to an ICameraUpdateFactoryDelegate that must be installed via setDelegate by the active maps backend (e.g. the vtm backend). getDelegate() throws IllegalStateException when no backend has registered, so any static factory method like newCameraPosition fails.","triggerScenarios":"Calling CameraUpdateFactory.newCameraPosition(...)/newLatLngZoom(...)/newLatLngBounds(...) before the map backend initialized — typically before any MapsInitializer or map fragment/view creation, or in a plain non-microG unit test.","commonSituations":"Creating CameraUpdate objects in Application.onCreate or a ViewModel before the map view exists; using microG maps classes on a device where no backend registered the delegate; running Robolectric/JUnit tests without setting a fake delegate.","solutions":["Obtain/initialize the map view (or call MapsInitializer / backend init) before creating CameraUpdate objects via CameraUpdateFactory","Ensure the microG maps backend is actually present and loaded so it calls CameraUpdateFactory.setDelegate(...)","In tests, install a mock ICameraUpdateFactoryDelegate via CameraUpdateFactory.setDelegate before exercising the factory"],"exampleFix":"// before\nCameraUpdate update = CameraUpdateFactory.newCameraPosition(pos); // delegate null\nmap.moveCamera(update);\n// after\nSupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);\nmapFragment.getMapAsync(googleMap -> {\n    CameraUpdate update = CameraUpdateFactory.newCameraPosition(pos);\n    googleMap.moveCamera(update);\n});","handlingStrategy":"try-catch","validationCode":"// only build camera updates after the map is initialized\nmapFragment.getMapAsync(googleMap -> {\n    CameraUpdate u = CameraUpdateFactory.newCameraPosition(pos);\n    googleMap.moveCamera(u);\n});","typeGuard":null,"tryCatchPattern":"try { CameraUpdateFactory.newCameraPosition(pos); } catch (IllegalStateException e) { /* defer until map initialized */ }","preventionTips":["Create CameraUpdate objects only from inside getMapAsync/onMapReady callbacks","Never use CameraUpdateFactory in Application.onCreate or ViewModels before map init","For unit tests, install a fake delegate via CameraUpdateFactory.setDelegate"],"tags":["android","maps","initialization","camera"],"backgroundTag":"module-init-failed","analyzedSha":"157c9d86ac46c195a86c2f15ab55c84036223f95","analyzedAt":"2026-09-06T17:27:33.892Z","contentChangedAt":"2026-09-06T17:27:33.892Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}