Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert.alert AlertManager with params exception

Tags:

react-native

I'm trying to sort out this error message:

Exception '-[_NSDisctionary0 length]: unrecognized selector sent to instance 0x78964120' was thrown while invoking alerWithArgs on target AlertManager with params

It's coming from my line of code:

const response.error = 'bad credentials'
Alert.alert('Login error', response.error, [{ text: 'Ok' }])

Even when I copy/paste from Facebook documentation I get the error:

Alert.alert(
      'Alert Title',
      'My Alert Msg',
      [
        {text: 'Ask me later', onPress: () => console.log('Ask me later pressed')},
        {text: 'Cancel', onPress: () => console.log('Cancel Pressed'), style: 'cancel'},
        {text: 'OK', onPress: () => console.log('OK Pressed')},
      ]
    )

The component is imported and all, obvious from the error message. I guess.

Has anyone come across this? Don't know what to make of it?

like image 618
fozzarelo Avatar asked Jan 30 '17 18:01

fozzarelo


4 Answers

Using expo, I kept running into this issue because I would forget to add both of the string arguments needed:

Alert.alert(
  'Alert Title',
  'My Alert Msg',
  [ ...

Alert.alert explicitly needs the first for the title of the alert and the second for the message. I can still replicate the issue: if you omit one of the strings once and you get this error, the message will still keep coming up - even if you have subsequently passed the correct string arguments - unless both the app AND the emulator/expo are restarted.

Doing so fixed the issue 100% of the times

like image 83
Stephanos Avatar answered Nov 19 '22 03:11

Stephanos


well very late for this user, but adding this in here just in case someone else finds it useful.

managed to cause this issue by creating an alert in expo without the message, it just had title and buttons.

It caused the error mentioned above and not only that it then broke expo essentially and caused every other alert to fail aswell from then on looking like the issue the poster had aswell. I had to close the expo app fully not just reload and of course add in an empty '' for the message.

like image 29
Ashley Alvarado Avatar answered Nov 19 '22 02:11

Ashley Alvarado


Restart your expo will fix this problem

like image 22
Kevin Zhang Avatar answered Nov 19 '22 03:11

Kevin Zhang


To anyone seeing this, this is a bug of the expo that once you get the Alert. alert the wrong without adding the description parameter in the expo, it will show the error. The error will last ever long unless you restart the packager and expo!

Solution: Restart the package!

like image 2
Rishav Kumar Avatar answered Nov 19 '22 01:11

Rishav Kumar