Skip to content

Error on real device when it works on simulator #14277

@andreecosta

Description

@andreecosta

Hey!
I need some help here.
When I run my app on simulator it works just fine, everything works.
But when I run it on my iPhone, on debug mode, when I click a specific button I get this error:

null is not an object (evaluating "this.state.value.map")

I've been getting this kind of errors alot when trying to map data to a fetch and then saving the data that comes from that fetch... It's hard to explain but I found a workaround to make it work, and It works on simulator. But on my device it won't (I mean, I guess it's because of that Im getting the error). Has anyone experienced this?

Here is the code I am getting the error from:

  getData(){
    const promises = this.state.value.map((item, index) =>
      fetch(`http://ws.autocompraevenda.net/consilcar/portalacv_ws.asmx/GetDetalhesViatura?CarID=${item}`)
       .then(response => response.json())
    )
    Promise.all(promises).then(values => this.setState({values: flatten(values), isLoading: false}))
  }

when values is empty, render runs this code:

    if(this.state.values.length === 0)
    {
      return(
        <View style={{ flex: 1, backgroundColor: 'white' }}>
          <NavigationBar
            tintColor='#1f1f1f'
            statusBar={{style: 'light-content'}}
            title={<NavbarTitle/>}
            leftButton={
              <NavbarLeft
                onPress={() => goBack()}
              />}
          />
          <View style={{ flex: 1, alignItems: 'center', flexDirection:'row', justifyContent:'center'}}>
            <Text style={styles.text2}>
              No Data!
            </Text>
          </View>
        </View>
      );
    }

this works fine on simulator as I said, if there is no data I get a screen saying No Data!, if there is, it just shows it...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions