NullPointerException with string-array in Spinner

后端 未结 2 1820
花落未央
花落未央 2020-12-20 17:10

First app and so really new at android (played around about a year ago but nothing came of it), decent at programming. Wanting to make sure app renders on a phone, no functi

2条回答
  •  梦毁少年i
    2020-12-20 17:50

    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference
        at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:394)
        at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
        at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:193)
        at android.widget.Spinner.onMeasure(Spinner.java:482)
    

    This tells you that the error was measuring the Spinner. More exactly, one of the strings that should be displayed inside it is null.

    The most likely cause is a problem with the @array/arraySplitr resource. Is it a valid string-array resource as defined in the documentation?

    This:

    
        2
        ...
    

    should be instead:

    
        2
        ...
    

    The array element is for Typed Arrays. String arrays must use string-array.

提交回复
热议问题