Adapter的getView方法返回了null

Android 3xcn.com@站长2021年12月7日 pm12:12发布3年前 (2021)更新
0
导航号,我的单页导航
目录

前言

这个是很简单的问题,就是适配器(比如BaseAdapter)中的getView()返回了null,是如下:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         // ...
        return null;
    }

修改方法就是返回初始化过的convertView

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         // ...
        return convertView;
    }

这个都是自己粗心大意导致的,记录于此,以示警戒。

正文

下面是异常的日志打印:

11-22 23:35:00.404 25866 25866 E AndroidRuntime: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getImportantForAccessibility()' on a null object reference
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.AbsListView.obtainView(AbsListView.java:2383)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.ListView.makeAndAddView(ListView.java:2052)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.ListView.fillDown(ListView.java:786)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.ListView.fillFromTop(ListView.java:847)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.ListView.layoutChildren(ListView.java:1826)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.AbsListView.onLayout(AbsListView.java:2165)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(ActionBarOverlayLayout.java:536)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:323)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.ViewGroup.layout(ViewGroup.java:6194)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1812)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1656)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.widget.LinearLayout.onLayout(LinearLayout.java:1565)
11-22 23:35:00.404 25866 25866 E AndroidRuntime:        at android.view.View.layout(View.java:20672)

参考文章

抱歉。由于之前忘记备注,无法回忆看到谁的文章了。

版权声明 1、 本站名称: 91易搜
2、 本站网址: https://www.91es.com/
3、 本站文章: 部分来源于网络,仅供站长学习和参考,若侵权请留言
导航号,我的单页导航

暂无评论

评论审核已启用。您的评论可能需要一段时间后才能被显示。

暂无评论...