Ошибка с заполнением Spinner Android

112
05 января 2021, 04:30

Хочу полученные результаты от сервера закинуть в Spinner, но выкидывает ошибку:

Traceback

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.ddstudio.usatuschedule, PID: 3969
    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:445)
        at android.widget.ArrayAdapter.getView(ArrayAdapter.java:407)
        at android.widget.AbsSpinner.onMeasure(AbsSpinner.java:204)
        at android.widget.Spinner.onMeasure(Spinner.java:602)
        at android.support.v7.widget.AppCompatSpinner.onMeasure(AppCompatSpinner.java:421)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1167)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:687)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:21998)
        at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1638)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:21998)
        at android.support.v4.widget.SwipeRefreshLayout.onMeasure(SwipeRefreshLayout.java:641)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1167)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:687)
        at android.view.View.measure(View.java:21998)
        at android.support.constraint.ConstraintLayout.internalMeasureChildren(ConstraintLayout.java:1227)
        at android.support.constraint.ConstraintLayout.onMeasure(ConstraintLayout.java:1572)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:733)
        at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:95)
        at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1556)
        at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:803)
        at android.view.View.measure(View.java:21998)
        at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1119)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
E/AndroidRuntime:     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1514)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:806)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:685)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6580)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:721)
        at android.view.View.measure(View.java:21998)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2410)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1498)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1751)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
        at android.view.Choreographer.doCallbacks(Choreographer.java:723)
        at android.view.Choreographer.doFrame(Choreographer.java:658)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

Что уходит от сервера:

[{"id":"1","number":"2"},{"id":"2","number":"4"},{"id":"3","number":"6"},{"id":"4","number":"8"},{"id":"5","number":"10"},{"id":"6","number":"12"},{"id":"7","number":"14"},{"id":"8","number":"16"},{"id":"9","number":"5"},{"id":"10","number":"7"},{"id":"11","number":"9"},{"id":"12","number":"11"},{"id":"13","number":"13"},{"id":"14","number":"15"},{"id":"15","number":"17"},{"id":"16","number":"1"},{"id":"17","number":"3"},{"id":"18","number":"18"},{"id":"19","number":"19"},{"id":"20","number":"21"},{"id":"21","number":"22"},{"id":"22","number":"20"},{"id":"23","number":"23"},{"id":"24","number":"24"},{"id":"25","number":"34"},{"id":"26","number":"35"},{"id":"27","number":"28"},{"id":"28","number":"25"},{"id":"29","number":"26"},{"id":"30","number":"27"},{"id":"31","number":"29"},{"id":"32","number":"30"},{"id":"33","number":"31"},{"id":"34","number":"32"},{"id":"35","number":"33"},{"id":"36","number":"37"},{"id":"37","number":"38"},{"id":"38","number":"36"},{"id":"39","number":"40"},{"id":"40","number":"41"},{"id":"41","number":"42"},{"id":"42","number":"39"},{"id":"43","number":"43"}]

Model

public class Week {
    private int id;
    private String name;
    public Week(int id, String name) {
        this.id = id;
        this.name = name;
    }
    public int getId() {
        return id;
    }
    public String getName() {
        return name;
    }
}

APIService

public interface APIService {
    @GET("v1/semesters")
    Single<List<Semester>> getSemesters();
    @GET("v1/groups")
    Single<List<GroupStudents>> getGroups();
    @GET("v1/weeks")
    Single<List<Week>> getWeeks();
}

Presenter

public void getWeeks(){
        mCompositeDisposable.add(
                ApiUtils.getApi()
                        .getWeeks()
                        .subscribeOn(Schedulers.io())
                        .observeOn(AndroidSchedulers.mainThread())
                        .subscribe(
                                response -> getViewState().showWeeks(response)
                        )
        );
    }

Fragment

@Override
    public void showWeeks(List<Week> weeks) {
        List<String> weeksNumbers = new ArrayList<>();
        for (Week week: weeks) {
            weeksNumbers.add(week.getName());
        }
        adapterNumbersWeeks = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, weeksNumbers);
        mSpinnerNumbersWeeks.setAdapter(adapterNumbersWeeks);
    }

Такое ощущение, что данные не те приходят, но я не могу посмотреть так как вывод response в Presenter, выводит просто список созданных экземпляров

[com.ddstudio.usatuschedule.data.Week@67c479c, com.ddstudio.usatuschedule.data.Week@f6435a5, com.ddstudio.usatuschedule.data.Week@8a14d7a, ...

READ ALSO
Не могу создать executable JAR-архив

Не могу создать executable JAR-архив

Пытаюсь поподробнее разобраться с ручной компиляцией java-проектов и появилась задача создать простой выполняемый jar-архивИмеется файл:

116
Перезагрузка скриптов

Перезагрузка скриптов

Возможно ли на JS динамически перезагрузить подключенные скрипты (обновить их кэш - загрузить scriptjs?time=111 с текущим значением времени)?

94
Не могу понять тестовое задание js

Не могу понять тестовое задание js

Есть тестовое задание tutu-ru (просто решил попрактиковаться )со следующим текстом:

88