滚动时更新适配器会导致GridLayoutManager.getOpticalLeft()

时间:2015-11-05 14:14:00

标签: android leanback

我正在使用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());

showsAdapterArrayObjectAdapter的一个实例。这是此类的addAll方法:

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

因此,您可以看到此方法通知适配器。

我还能做些什么来解决此错误或至少阻止异常?

0 个答案:

没有答案