React-native-picker-select: Android crash on press select

Created on 8 Jul 2019  路  4Comments  路  Source: lawnstarter/react-native-picker-select

Describe the bug

When i click on the select on Android the application crash.

This is the log from the Android Studio console:

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.wtaapp, PID: 4475
    com.facebook.react.bridge.NoSuchKeyException: label
        at com.facebook.react.bridge.ReadableNativeMap.getNullableValue(ReadableNativeMap.java:137)
        at com.facebook.react.bridge.ReadableNativeMap.getNullableValue(ReadableNativeMap.java:141)
        at com.facebook.react.bridge.ReadableNativeMap.getString(ReadableNativeMap.java:192)
        at com.facebook.react.views.picker.ReactPickerManager$ReactPickerAdapter.getView(ReactPickerManager.java:126)
        at com.facebook.react.views.picker.ReactPickerManager$ReactPickerAdapter.getDropDownView(ReactPickerManager.java:112)
        at android.widget.Spinner$DropDownAdapter.getDropDownView(Spinner.java:1022)
        at android.widget.Spinner$DropDownAdapter.getView(Spinner.java:1018)
        at android.widget.Spinner.measureContentWidth(Spinner.java:860)
        at android.widget.Spinner$DropdownPopup.computeContentWidth(Spinner.java:1255)
        at android.widget.Spinner$DropdownPopup.show(Spinner.java:1281)
        at android.widget.Spinner.performClick(Spinner.java:784)
        at android.support.v7.widget.AppCompatSpinner.performClick(AppCompatSpinner.java:443)
        at android.view.View$PerformClick.run(View.java:24931)
        at android.os.Handler.handleCallback(Handler.java:808)
        at android.os.Handler.dispatchMessage(Handler.java:101)
        at android.os.Looper.loop(Looper.java:166)
        at android.app.ActivityThread.main(ActivityThread.java:7523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)

To Reproduce

This is my configuration:

render() {
    let styleShadow = {}
    if (this.props.shadow) {
      styleShadow = {
        shadowColor: config.colors.black,
        shadowOffset: { width: 0, height: 3 },
        shadowOpacity: 0.15
      }
    }

    const style = [{
      paddingLeft: this.props.icon ? 40 : 15,
      paddingRight: 15,
      paddingTop: 10,
      paddingBottom: 10,
      backgroundColor: config.colors.white,
      borderColor: this.state.borderColor,
      borderWidth: 1,
      fontFamily: config.fonts.poppins,
      borderRadius: 10,
    }, styleShadow]

    return (
      <View style={[{
        marginBottom: 15,
        position: 'relative'
      }]}>
        <PickerSelect
          style={{
            inputAndroid: style,
            inputIOS: style,
            done: { color: config.colors.red },
            placeholder: { color: config.colors.black }
          }}
          items={this.props.items}
          onValueChange={this.props.onChangeText}
          placeholder={this.props.placeholder}
          value={this.props.value}
          useNativeAndroidPickerStyle={false}
          doneText="Confirm"
        />
      </View>
    )
  }

Smartphone:

  • Device: Huawei P8 lite 2017
  • OS: Android 8.0.0
  • react-native-picker-select version: 6.2.0
  • react-native version: 0.59.5
  • react version: 16.8.3

Most helpful comment

@gregogalante, noticed you closed this issue. Did you find a resolution to this? We're getting the exact same error whenever we pass an empty array of items to the picker. Same details / env as you.

Right now we're working around it by populating optimistically and then loading in the data from the API so the items are never empty.

My problem was related to the placeholder props. I pass a string as props insthead of an object with same keys like an option object.

All 4 comments

@gregogalante, noticed you closed this issue. Did you find a resolution to this? We're getting the exact same error whenever we pass an empty array of items to the picker. Same details / env as you.

Right now we're working around it by populating optimistically and then loading in the data from the API so the items are never empty.

@gregogalante, noticed you closed this issue. Did you find a resolution to this? We're getting the exact same error whenever we pass an empty array of items to the picker. Same details / env as you.

Right now we're working around it by populating optimistically and then loading in the data from the API so the items are never empty.

My problem was related to the placeholder props. I pass a string as props insthead of an object with same keys like an option object.

I ran into the same issue. @gregogalante's solution fixed my issue.

I was also experiencing the same crash. Similar solution to above. I was already passing in a placeholder object like so -

placeholder={{label: someLabel, value: someValue}}

BUT, I discovered someLabel and someValue were undefined. So I had to ensure that those values were getting thru, and then it worked.

Was this page helpful?
0 / 5 - 0 ratings