前言
这个是很简单的问题,就是适配器(比如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)
参考文章
抱歉。由于之前忘记备注,无法回忆看到谁的文章了。
© 版权声明