0

私はleanbackライブラリを使用しています: HorizontalGridView+ ArrayObjectAdapter.

他にも同様の質問がたくさんあることを知っています。解決策は、アダプターに変更があったことを通知することです。

しかし、私の場合、アダプターに通知しても、高速スクロール中にこのエラーが発生します。

11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime: FATAL EXCEPTION: main
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime: Process: com.example.app, PID: 25575
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime: java.lang.NullPointerException
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.getOpticalLeft(GridLayoutManager.java:950)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.getViewMin(GridLayoutManager.java:966)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.access$3300(GridLayoutManager.java:50)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager$2.getEdge(GridLayoutManager.java:1518)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.Grid.removeInvisibleItemsAtEnd(Grid.java:385)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.removeInvisibleViewsAtEnd(GridLayoutManager.java:1612)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.scrollDirectionPrimary(GridLayoutManager.java:1979)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v17.leanback.widget.GridLayoutManager.scrollHorizontallyBy(GridLayoutManager.java:1905)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.support.v7.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:3773)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:772)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.view.Choreographer.doCallbacks(Choreographer.java:585)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:554)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:758)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.os.Handler.handleCallback(Handler.java:733)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.os.Handler.dispatchMessage(Handler.java:95)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.os.Looper.loop(Looper.java:136)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:5017)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at java.lang.reflect.Method.invokeNative(Native Method)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at java.lang.reflect.Method.invoke(Method.java:515)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
11-05 18:57:35.335 25575-25575/com.example.app E/AndroidRuntime:     at dalvik.system.NativeStart.main(Native Method)

次のコードを使用してアダプターを更新します。

showsAdapter.addAll(showsAdapter.size(), day.getShows());

showsAdapterのインスタンスですArrayObjectAdapter。このクラスのaddAllメソッドは次のとおりです。

public void addAll(int index, Collection items) {
        int itemsCount = items.size();
        if (itemsCount == 0) {
            return;
        }
        mItems.addAll(index, items);
        notifyItemRangeInserted(index, itemsCount);
    }

ご覧のとおり、このメソッドはアダプターに通知します。

このエラーを修正するか、少なくとも例外を防ぐために他に何ができますか?

4

0 に答える 0