新浪微博 AbsListView.obtainView调用关系

日前遇到Bug,出现

09-01 16:26:42.916 15952 15952 E AndroidRuntime: FATAL EXCEPTION: main
09-01 16:26:42.916 15952 15952 E AndroidRuntime: Process: com.sina.weibo, PID: 15952
09-01 16:26:42.916 15952 15952 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setDrawingCacheBackgroundColor(int)' on a null object reference
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.AbsListView.obtainView(AbsListView.java:2360)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.ListView.makeAndAddView(ListView.java:1882)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.ListView.fillDown(ListView.java:704)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.ListView.fillSpecific(ListView.java:1362)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.ListView.layoutChildren(ListView.java:1669)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.widget.AbsListView.onLayout(AbsListView.java:2151)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.view.View.layout(View.java:15686)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.view.ViewGroup.layout(ViewGroup.java:5107)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at com.sina.weibo.view.PullDownView.onLayout(PullDownView.java:676)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.view.View.layout(View.java:15686)
09-01 16:26:42.916 15952 15952 E AndroidRuntime: 	at android.view.ViewGroup.layout(ViewGroup.java:5107)
即空对象使用问题。

这里很明确,是

AbsListView中的obtainView函数报错;

这个函数里面有一句代码

        final View child = mAdapter.getView(position, scrapView, this);

拿到child也就是view,但没有进行判断null,而是直接使用。非常的sb。

因为mAdapter的继承者过多,最后找到新浪微波是调用HeaderViewListAdapter.java中的

    public View getView(int position, View convertView, ViewGroup parent) {
    Log.d("stl","HVLA getView");
        // Header (negative positions will throw an IndexOutOfBoundsException)
        int numHeaders = getHeadersCount();
        if (position < numHeaders) {
            return mHeaderViewInfos.get(position).view;
        }

        // Adapter
        final int adjPosition = position - numHeaders;
        int adapterCount = 0;
        if (mAdapter != null) {
            adapterCount = mAdapter.getCount();
            if (adjPosition < adapterCount) {
                return mAdapter.getView(adjPosition, convertView, parent);
            }
        }

        // Footer (off-limits positions will throw an IndexOutOfBoundsException)
        return mFooterViewInfos.get(adjPosition - adapterCount).view;
    }

目前刚分析到这里,由于其他紧急问题需要分析。后续跟进后,更新文章


E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.hjschoolhelper210301201_1, PID: 13135 java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference at com.example.hjschoolhelper210301201_1.ClubinfoAdpter.getView(ClubinfoAdpter.java:44) at android.widget.AbsListView.obtainView(AbsListView.java:2458) at android.widget.ListView.makeAndAddView(ListView.java:2067) at android.widget.ListView.fillDown(ListView.java:793) at android.widget.ListView.fillFromTop(ListView.java:855) at android.widget.ListView.layoutChildren(ListView.java:1838) at android.widget.AbsListView.onLayout(AbsListView.java:2255) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at androidx.constraintlayout.widget.ConstraintLayout.onLayout(ConstraintLayout.java:1855) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:536) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1891) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1729) at android.widget.LinearLayout.onLayout(LinearLayout.java:1638) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:332) at android.widget.FrameLayout.onLayout(FrameLayout.java:270) at com.android.internal.policy.DecorView.onLayout(DecorView.java:799) at android.view.View.layout(View.java:23693) at android.view.ViewGroup.layout(ViewGroup.java:6413) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:3999) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3372) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2328) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9087) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239) at android.view.Choreographer.doCallbacks(Choreographer.java:899) at android.view.Choreographer.doFrame(Choreographer.java:832) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7872) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
05-17
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值