首页 > 解决方案 > 在 React-Native 中发生意外错误“index = 8, count = 2”

问题描述

尝试在 MapView 中呈现文本时。我正面临这个错误。

每当我创建一个Textin 时,RealTimePosition.js我都会收到 Error index = 8, count = 2。我不明白为什么会发生此错误以及如何修复它。请帮我解决它。

在 IOS 设备中工作正常

Component where the error is occurring

class RealTimePosition extends Component{

 ....
 return(
    <View>

        <View> 
      <Text>
     //after removing this View and Text code is working fine but adding the View gives me error.
      </Text>
     </View>

      {
        showBus?
      <MapView.Marker
      coordinate = {realTimeData}
      anchor = {{x:0.5, y:0.5}}
      flat = {true}
      >
         <Image
                source={require("../../assets/images/schoolBus.png")}
                 style = {{ width:42, height:42, transform: [{ rotate : 
                 `${rotation}deg`}]}}
              />
        </MapView.Marker>:
        null
      }
    </View>

  )
 }

calling RealTimePosition from this MapAnimateToRegion.js

  class MapAnimateToRegion extends Component{
  ...
  return(
  <View>
 <MapView>
      {
        CrossButtonvisible?
      <RealTimePosition 
      routeId = {routeId}
      polyLinedata = {this.state.pickData}
      HomeCoordinate = {this.HomeCoordinate}
      onRef={ref => (this.parentReference = ref)}
      parentReference = {this.parentMethod.bind(this)}
      />:
      null
      }
       </MapView>
  </View>
   )
  } 

parent Component

  class Parent extends Component{
   ....
   render(){
  if(this.state.currentScreen == "showMap")
  {
    const {stopsData} = this.state;
    const {stopId} = this.state;
    const {stopSequence} = this.state;
    const {routeId} = this.state;
    const {pickData} =this.state

    return(
      <View style={styles.container}>
        <MapAnimateToRegion
        stopsData = {stopsData}
        stopId = {stopId}
        routeId = {routeId}
        stopSequence = {stopSequence}
        Data = {pickData}
        onRef={ref => (this.TimeparentReference = ref)}
        TimeparentReference = {this.onTimeChange.bind(this)}
        />

   </View>
 )

} 

标签: react-nativereact-native-android

解决方案


推荐阅读