ListActivity에 대한 AbsListView.obtainView의 ListView에서 충돌이 발생합니다.
다음과 같이 ContentObserver를 사용하여 ListActivity에서 콘텐츠 업데이트를보고 있습니다.
protected void onCreate(Bundle savedState)
{
super.onCreate(savedState);
ContentResolver cr = getContentResolver();
Cursor cursor = cr.query(TrackHeader.CONTENT_URI, sTrackListProjection, null, null, null);
startManagingCursor(cursor);
this.mAdapter = new TrackHeaderDataAdapter(this, R.layout.track_list_item, cursor, sTrackListProjection, null);
setListAdapter(mAdapter);
Handler handler = new Handler();
mTrackHeaderObserver = new ContentObserver(handler) {
@Override
public boolean deliverSelfNotifications() {
return false;
}
@Override
public void onChange(boolean selfChange) {
super.onChange(selfChange);
ContentResolver cr = getContentResolver();
mAdapter.changeCursor(cr.query(TrackHeader.CONTENT_URI, sTrackListProjection, null, null, null));
}
};
getContentResolver().registerContentObserver (TrackHeader.CONTENT_URI, true, mTrackHeaderObserver);
}
이 콘텐츠 관찰자는 괜찮은 것 같습니다 .UI 스레드에서 다시 호출되지만 기본 ListView에서 예상대로 다음과 같은 임의의 충돌이 발생합니다.
02-21 14:06:00.440: ERROR/AndroidRuntime(739): java.lang.NullPointerException
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.AbsListView.obtainView(AbsListView.java:1276)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.ListView.makeAndAddView(ListView.java:1668)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.ListView.fillDown(ListView.java:637)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.ListView.fillSpecific(ListView.java:1224)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.ListView.layoutChildren(ListView.java:1499)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.AbsListView.onLayout(AbsListView.java:1113)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.View.layout(View.java:6830)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.ViewRoot.performTraversals(ViewRoot.java:996)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.os.Handler.dispatchMessage(Handler.java:99)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.os.Looper.loop(Looper.java:123)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at android.app.ActivityThread.main(ActivityThread.java:4363)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at java.lang.reflect.Method.invokeNative(Native Method)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at java.lang.reflect.Method.invoke(Method.java:521)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-21 14:06:00.440: ERROR/AndroidRuntime(739): at dalvik.system.NativeStart.main(Native Method)
02-21 14:09:56.159: ERROR/AndroidRuntime(749): ERROR: thread attach failed
02-21 14:09:59.480: ERROR/AndroidRuntime(760): ERROR: thread attach failed
02-21 14:12:19.449: ERROR/AndroidRuntime(778): ERROR: thread attach failed
02-21 14:12:22.779: ERROR/AndroidRuntime(789): ERROR: thread attach failed
02-21 14:12:26.479: ERROR/gralloc(51): [unregister] handle 0x3f13b8 still locked (state=40000001)
전에 이런 걸 본 사람은 누구나 며칠 동안이 문제에 당황했습니다 ...
팀
비슷한 스택 추적이 있었고 특정 경우에 getView () 메서드에서 null을 반환한다는 것을 발견했습니다.
목록이 있고 BaseAdapter 또는 Adapter를 확장하여 사용자 지정 목록을 가져 오는 경우 getView가 null이 아닌 값을 반환하는지 확인합니다.
탭 뷰가 있고 조각 중 하나가 Adapter / BaseAdapter를 재정의하는 목록이고 getView가 null을 반환하면이 문제가 발생합니다.
If you are using a static class ViewHolder to store your view items in the adapter, you may forgot to set the viewHolder object as the tag of the convertView. E.g:
if (convertView == null) {
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
convertView = mInflater.inflate(R.layout.adapter_drivers_and_riders, null);
holder = new ViewHolder();
holder.tvDate = (TextView)convertView.findViewById(R.id.tvDate);
holder.tvTime = (TextView)convertView.findViewById(R.id.tvTime);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
In my case, I was not using a Cursor but having the same issue, I figured it out that i forgot to set the tag as viewHolder to convertView so when the first adapter views are created for the listview, it is ok but when you scroll and recycling mechanism works, it crashes since it can't restore the viewHolder from convertView.
Just in case, I wanted to mention.
I have not used changeCursor()
. And, since the query you used to create the Cursor
is the same as the query you are using to "change" the cursor, I'd dump the changeCursor()
call outright and just call requery()
on the Cursor
you have.
ReferenceURL : https://stackoverflow.com/questions/2307688/crash-in-listview-at-abslistview-obtainview-for-listactivity
'programing' 카테고리의 다른 글
ADB 드라이버 및 Windows 8.1 (0) | 2020.12.27 |
---|---|
JavaScript에서 배열의 모든 요소를 정수로 변환하는 방법은 무엇입니까? (0) | 2020.12.26 |
정수가 PHP에서 숫자 범위 내에 있는지 확인하는 방법은 무엇입니까? (0) | 2020.12.26 |
하단 내비게이션 바 아이콘 상단에 배지 표시 (0) | 2020.12.26 |
우분투에서 기본 Python 버전을 python3으로 설정할 수 없습니다. (0) | 2020.12.26 |