huxq17 / XRefreshView

一个万能的android下拉上拉刷新的框架,完美支持recyclerview
1.7k stars 501 forks source link

Found a crash !!! #100

Open hurricane08 opened 7 years ago

hurricane08 commented 7 years ago

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOverScrollMode(int)' on a null object reference at com.andview.refreshview.XRefreshContentView.setContentView(XRefreshContentView.java:72) at com.andview.refreshview.XRefreshView.attachContentView(XRefreshView.java:266) at com.andview.refreshview.XRefreshView.access$400(XRefreshView.java:33) at com.andview.refreshview.XRefreshView$1.onGlobalLayout(XRefreshView.java:220) at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:912) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1936) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1093) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6010) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5912) at java.lang.reflect.Method.invoke(Method.java) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1405) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1200)

huxq17 commented 7 years ago

什么情况出现的?

hurricane08 commented 7 years ago

不是测试出来的,没有复现过。

huxq17 commented 7 years ago

项目里是怎么用的?能给个demo么?

hurricane08 commented 7 years ago
<com.andview.refreshview.XRefreshView
        android:id="@+id/article_refresh_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent">
        <android.support.v7.widget.RecyclerView
            android:id="@+id/refresh_recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"/>
</com.andview.refreshview.XRefreshView>
refreshLayout = ViewUtils.findViewById(this, R.id.article_refresh_layout);
        refreshLayout.setMoveForHorizontal(true);
        refreshLayout.setPullRefreshEnable(true);
        refreshLayout.setAutoLoadMore(true);

        recyclerView = ViewUtils.findViewById(this, R.id.refresh_recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        adapter = new ArticleListAdapter();
        recyclerView.setAdapter(adapter);
        recyclerView.setPadding(0, 0, 0, Utils.getNavigationBarHeight(getContext()));
        recyclerView.setClipToPadding(false);

        CustomHeaderView headerView = new CustomHeaderView(getContext());
        CustomFooterView footerView = new CustomFooterView(getContext());
        refreshLayout.setCustomHeaderView(headerView);
        adapter.setCustomLoadMoreView(footerView);
hurricane08 commented 7 years ago

可以加个NPE保护代码么?

huxq17 commented 7 years ago

我是想知道refreshLayout 在哪些地方find id 的。找不到根本原因加npe保护代码也没用啊。

hurricane08 commented 7 years ago

场景是:pageView,每一页是个FrameLayout,refreshLayout是其子view,然后find id的代码在这个FrameLayout的onFinishInflate中

@Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        ……
        refreshLayout = ViewUtils.findViewById(this, R.id.article_refresh_layout);
        refreshLayout.setMoveForHorizontal(true);
        refreshLayout.setPullRefreshEnable(true);
        refreshLayout.setAutoLoadMore(true);
       ……
Hichencha commented 7 years ago

您好setOverScrollMode() 这个问题您解决了吗?