Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.maps.GoogleMap.setPadding(int, int, int, int)' on a null object reference
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- android, react-native, typescript
- Domain
- mobile
Research direction
Start by tracing the Android mapPadding prop handling and the map lifecycle during the background-to-foreground transition described in the sample. Reproduce the crash with the provided TSX example under the new architecture, then verify that repeatedly unmounting and remounting the map no longer crashes when the map reference is null.
Written by the indexing model from the issue text.
Description
Summary
The logic applies the mapPadding prop calls map.setPadding. If map is null, app crashes.
Reproducible sample code
import React, {useEffect, useState} from 'react';
import {AppState} from 'react-native';
import MapView, {PROVIDER_GOOGLE} from 'react-native-maps';
export default function App() {
const [appState, setAppState] = useState(AppState.currentState); // 'active' | 'background' | 'inactive'
useEffect(() => {
const sub = AppState.addEventListener('change', next => setAppState(next));
return () => sub.remove();
}, []);
if (appState === 'background') {
return null;
}
return (
<MapView
style={{flex: 1}}
provider={PROVIDER_GOOGLE}
mapPadding={{bottom: 160}}
initialRegion={{
latitude: 42,
longitude: 30,
latitudeDelta: 1,
longitudeDelta: 1,
}}
/>
);
}
Steps to reproduce
Use the new architecture, and set map padding via props. Include logic that unmounts the map when the app is backgrounded (uncommon, but used in some cases to release memory).
Background the app. Resume the app. Repeat until the crash occurs.
Expected result
Don't crash.
Actual result
Crashes.
React Native Maps Version
1.26.20
What platforms are you seeing the problem on?
Android
React Native Version
0.83.1
What version of Expo are you using?
Not using Expo
Device(s)
Samsung Galaxy S24
Additional information
No response
- Dominant language
- TypeScript
- Stars
- 16k
- Forks
- 5k
- Avg merge
- 9d 9h
- Merged PRs (30d)
- 3
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from react-native-maps/react-native-maps
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
react-native-maps/react-native-maps#5987 · 1 comment ·
All issues in react-native-maps/react-native-maps
Similar issues
-
Type/Bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OpenNSW/nsw-srilanka#497 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
0xMiden/bridge-portal#132 ·
-
react-doctor severity:warning tech-debt
Difficulty 1/5 Under an hour Newbie friendliness 88/100
digidem/comapeo-cloud-app#403 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100