TableView icon indicating copy to clipboard operation
TableView copied to clipboard

Exception when the table is being shown

Open ehsanTC opened this issue 5 years ago • 3 comments

Hi I have used TableView version 0.8.9 in my app. When the table is starting to show rows, after some rows the below exception is arises:

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getLeft()' on a null object reference at com.evrencoskun.tableview.listener.scroll.HorizontalRecyclerViewListener.renewScrollPosition(HorizontalRecyclerViewListener.java:260) at com.evrencoskun.tableview.listener.scroll.HorizontalRecyclerViewListener.onInterceptTouchEvent(HorizontalRecyclerViewListener.java:149) at androidx.recyclerview.widget.RecyclerView.findInterceptingOnItemTouchListener(RecyclerView.java:3151) at androidx.recyclerview.widget.RecyclerView.dispatchToOnItemTouchListeners(RecyclerView.java:3122) at androidx.recyclerview.widget.RecyclerView.onTouchEvent(RecyclerView.java:3283) at android.view.View.dispatchTouchEvent(View.java:9187) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2644) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2351) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2651) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:2366) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2651) ....

The layout file for my table cell is just a textview inside a linear layout. Additionally the code for binding the cell is:

@Override
public void onBindCellViewHolder(@NonNull AbstractViewHolder holder, @Nullable Cell cellItemModel, int columnPosition, int rowPosition) {
    MyCellViewHolder viewHolder = (MyCellViewHolder) holder;
    viewHolder.setData(cellItemModel);
}

Do you know where is the problem?

ehsanTC avatar Feb 01 '20 10:02 ehsanTC

Hi @ehsanTC

To be able the test your case, Could you create this problem in the sample application?

evrencoskun avatar Feb 06 '20 11:02 evrencoskun

Unfortunately this happens very often. TableView sometimes does not restore cells when you navigate back from other fragment (on top of fragment with table) or swap between pages in ViewPager, when ViewPager's Page is also fragment with the table. So you return to the fragment with the TableView, it restores RowHeaders, ColumnHeaders, Corner, but not the cells. Cells are empty list. And when you touch that empty list - your crash with

java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getLeft()' on a null object reference
        at com.evrencoskun.tableview.listener.scroll.HorizontalRecyclerViewListener.renewScrollPosition(HorizontalRecyclerViewListener.java:260) 

Still can scroll Headers tho.

http://prntscr.com/w0mu8p

We still investigate why exactly this happens and how to fix it

KoTius avatar Dec 11 '20 15:12 KoTius

Hi @ehsanTC @KoTius The issue is related to how the viewpager2 manage with fragments, i.g. when you disable the TabLayoutMediator smoothScroll option the viewpager2 stop to recreate the fragments and the TableView doesn't restore the data, to prevent this behaviour you can call adapter.notifyDataSetChanged() in the fragment onResume() method

romansolo avatar Jan 22 '21 16:01 romansolo