日前遇到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;
}
目前刚分析到这里,由于其他紧急问题需要分析。后续跟进后,更新文章