NullPointerException with string-array in Spinner

后端 未结 2 1814
花落未央
花落未央 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条回答
  • 2020-12-20 17:38

    Your logcat has a NullPointerException.

    E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.hydr0dr4gon.splitrv2, PID: 10290 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)

    Something is not initialized. From your code I cannot see what it would be. Do you have an ArrayAdapter and if so you you initialize it and all the objects it contains? Or is your table just filled by your layout file? I would start looking at how your table is filled (based on the logcat) but I can't see specifically what the problem would be from the code you posted.

    0 讨论(0)
  • 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:

    <array name="arraySplitr">
        <item>2</item>
        ...
    

    should be instead:

    <string-array name="arraySplitr">
        <item>2</item>
        ...
    

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

    0 讨论(0)
自定义标题
段落格式
字体
字号
代码语言
提交回复
热议问题