Последняя проблема удаления утилиты Android RecyclerView (runtime)

У меня есть RecyclerView с настраиваемым элементом списка и с элементом CardView в двух разных Activities . Теперь я получаю ошибку, когда я удаляю последний оставшийся элемент из списка, я не менял никакого кода, связанного с этими acitivities или adapter или RecyclerView .

Ошибка:

 java.lang.NullPointerException at android.support.v7.widget.OrientationHelper$2.getDecoratedStart(OrientationHelper.java:316) at android.support.v7.widget.LinearLayoutManager.findOneVisibleChild(LinearLayoutManager.java:1633) at android.support.v7.widget.LinearLayoutManager.findFirstVisibleChildClosestToStart(LinearLayoutManager.java:1453) at android.support.v7.widget.LinearLayoutManager.computeScrollOffset(LinearLayoutManager.java:997) at android.support.v7.widget.LinearLayoutManager.computeVerticalScrollOffset(LinearLayoutManager.java:969) at android.support.v7.widget.RecyclerView.computeVerticalScrollOffset(RecyclerView.java:1175) at android.view.View.canScrollVertically(View.java:12745) at android.support.v4.view.ViewCompatICS.canScrollVertically(ViewCompatICS.java:35) at android.support.v4.view.ViewCompat$ICSViewCompatImpl.canScrollVertically(ViewCompat.java:940) at android.support.v4.view.ViewCompat.canScrollVertically(ViewCompat.java:1237) at android.support.v7.widget.RecyclerView$LayoutManager.onInitializeAccessibilityEvent(RecyclerView.java:6594) at android.support.v7.widget.RecyclerView$LayoutManager.onInitializeAccessibilityEvent(RecyclerView.java:6573) at android.support.v7.widget.LinearLayoutManager.onInitializeAccessibilityEvent(LinearLayoutManager.java:204) at android.support.v7.widget.RecyclerViewAccessibilityDelegate.onInitializeAccessibilityEvent(RecyclerViewAccessibilityDelegate.java:66) at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.onInitializeAccessibilityEvent(AccessibilityDelegateCompat.java:228) at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.onInitializeAccessibilityEvent(AccessibilityDelegateCompatJellyBean.java:56) at android.view.View.onInitializeAccessibilityEvent(View.java:5292) at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:5160) at android.view.View$AccessibilityDelegate.sendAccessibilityEventUnchecked(View.java:20325) at android.support.v4.view.AccessibilityDelegateCompatIcs.sendAccessibilityEventUnchecked(AccessibilityDelegateCompatIcs.java:117) at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateIcsImpl.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:210) at android.support.v4.view.AccessibilityDelegateCompat.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:358) at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:255) at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.sendAccessibilityEventUnchecked(AccessibilityDelegateCompatJellyBean.java:82) at android.view.View.sendAccessibilityEventUnchecked(View.java:5143) at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.run(ViewRootImpl.java:7653) at android.view.ViewRootImpl$SendWindowContentChangedAccessibilityEvent.runOrPost(ViewRootImpl.java:7679) at android.view.ViewRootImpl.postSendWindowContentChangedCallback(ViewRootImpl.java:6871) at android.view.ViewRootImpl.notifySubtreeAccessibilityStateChanged(ViewRootImpl.java:6944) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.ViewGroup.notifySubtreeAccessibilityStateChanged(ViewGroup.java:2746) at android.view.View.notifySubtreeAccessibi 

Здесь нет ничего похожего на мой код. Я использую dependencies :

 dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:21.0.+' compile 'com.android.support:recyclerview-v7:21.0.+' compile 'com.android.support:cardview-v7:21.0.+' compile 'com.google.android.gms:play-services:6.5.87' compile 'com.android.support:support-v4:21.0.3' compile 'se.emilsjolander:StickyScrollViewItems:1.+' compile 'net.i2p.android.ext:floatingactionbutton:1.8.0' compile 'com.afollestad:material-dialogs:0.6.4.7'} 

Любая идея, что может быть проблемой?

Я сделал обходной путь для этого, создав дочерний класс для LinearLayoutManager . Это неудачное решение, но, по крайней мере, оно будет работать, пока библиотека поддержки не устранит эту проблему …

 import android.content.Context; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.util.Log; import android.view.accessibility.AccessibilityEvent; public class LinearLayoutManagerWrapper extends LinearLayoutManager { private static final String TAG = "LinearLayoutManagerWrapper"; public LinearLayoutManagerWrapper(final Context context) { super(context); } @Override public void onInitializeAccessibilityEvent(final AccessibilityEvent event) { try { super.onInitializeAccessibilityEvent(event); } catch (final NullPointerException e) { Log.e(TAG, "NullPointerException in onInitializeAccessibilityEvent(" + event + ')', e); } } @Override public void onInitializeAccessibilityEvent(final RecyclerView.Recycler recycler, final RecyclerView.State state, final AccessibilityEvent event) { try { super.onInitializeAccessibilityEvent(recycler, state, event); } catch (final NullPointerException e) { Log.e(TAG, "NullPointerException in onInitializeAccessibilityEvent(" + recycler + ", " + state + ", " + event + ')', e); } } } 

Ошибка возникла из-за того, что одна из библиотек использует v7:22 библиотеку appcompat и recyclerview . Я перезаписал зависимость для использования v7: 21, написав:

 compile ('com.android.support:appcompat-v7:21.0.+'){force=true} compile ('com.android.support:recyclerview-v7:21.0.+'){force=true} 

Я еще не уверен, почему последняя версия v7: 22 дает ошибку при просмотре последнего элемента удаления.

Intereting Posts