BakerJQ / Android-InfiniteCards

An infinite card switching UI for Android, support custom animation 自定义实现神奇动效的卡片切换视图
Apache License 2.0
1.73k stars 204 forks source link

java.lang.NullPointerException: #12

Closed piyushmishra10 closed 5 years ago

piyushmishra10 commented 6 years ago

Attempt to invoke virtual method 'int android.widget.BaseAdapter.getCount()' on a null object reference

private void firstSetAdapter(BaseAdapter adapter) { if (mTransformerAnimAdd != null) { mIsAddRemoveAnim = true; } mCards = new LinkedList<>(); // mCards4JudgeZIndex = new ArrayList<>(); mCardCount = adapter.getCount(); (issue)

It's leading me to your firstSetAdapter. Tried many times other infinite views are working properly but after many attempts, your code is crashing on CardAnimationHelper class line 463.

Chaosxing commented 6 years ago

This method begins when the page created. This means you have to set a default and not empty BaseAdapter

mAdapter.registerDataSetObserver(new DataSetObserver(){
  Public void onChanged(){
    mAnimationHelper.notifyDataSetChanged(mAdapter);
  }
});

Although I found this in the code, I still did not change the data when BaseAdapter.notifyDataSetChanged. The author seems to have not updated for a long time. I am looking for the cause of the problem myself.