作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我正在使用 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。
关于android - ListView 在 AbsListView.obtainView 中为 ListActivity 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2307688/
我正在使用 ContentObserver 在 ListActivity 上观看内容更新,如下所示: protected void onCreate(Bundle savedState) {
我不知道从哪里开始调试。这是来自 logcat 的信息: 01-22 18:28:20.472: E/AndroidRuntime(10859): FATAL EXCEPTION: main 01-2
我是一名优秀的程序员,十分优秀!