react-native-maps: [Android] app crashes on markers mount
Hi, when I mount a map, all works fine. But, when props on my map component updates and I create markers, app crashes. iOS version works fine, crashes only on Android:
06-13 18:47:09.745 31797-31797/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.testapp, PID: 31797
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
at java.util.ArrayList.add(ArrayList.java:147)
at com.airbnb.android.react.maps.AirMapView.addFeature(AirMapView.java:284)
at com.airbnb.android.react.maps.AirMapManager.addView(AirMapManager.java:230)
at com.airbnb.android.react.maps.AirMapManager.addView(AirMapManager.java:26)
at com.facebook.react.uimanager.NativeViewHierarchyManager.manageChildren(NativeViewHierarchyManager.java:367)
at com.facebook.react.uimanager.UIViewOperationQueue$ManageChildrenOperation.execute(UIViewOperationQueue.java:175)
at com.facebook.react.uimanager.UIViewOperationQueue$2.run(UIViewOperationQueue.java:766)
at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:830)
at com.facebook.react.uimanager.GuardedChoreographerFrameCallback.doFrame(GuardedChoreographerFrameCallback.java:32)
at com.facebook.react.uimanager.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:125)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:797)
at android.view.Choreographer.doCallbacks(Choreographer.java:612)
at android.view.Choreographer.doFrame(Choreographer.java:580)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:785)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
My code looks like:
<MapView ref="map"
mapType="terrain"
style={styles.map}
region={this.state.region}
showsUserLocation={true}
zoomEnabled={false}
showsCompass={true}
rotateEnabled={true}
pitchEnabled={false}
followsUserLocation={false}
onRegionChangeComplete={this.onRegionChangeComplete}
onPanDrag={this.onPanDrag}>
{this.renderMapUrlTile()}
{this.props.markers.map((item, index) => {
let markerComponent;
if ((typeof item['type'] !== 'undefined') && (item.type == 'user')) {
markerComponent = <MapView.Marker coordinate={item}
image={require('./../../assets/img/icon-user-location.png')}/>
} else {
markerComponent =
<MapView.Marker coordinate={item}
image={require('./../../assets/img/icon-user-location2.png')}/>
}
return markerComponent;
})}
</MapView>
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Reactions: 7
- Comments: 15 (1 by maintainers)
Hello from the future: In case Android throws the same error and you are using a custom
<Marker />with a custom<Callout />: Order matters:In my case i’m adding react native
<Viewinside<MapViewApparently only accepts views with the MapView prefix. Like<MapView.Polyline,<MapView.Marker, etcI realized my mistake is that i added a <Text> within the <MapView> </MapView>. Not sure why, but it works after i removed it.
I encountered @sydneywu’s same error. @sydneywu Could you comment your removed the “it” if possible ?