android – 带对话框的StaleDataException

android – 带对话框的StaleDataException,第1张

概述我试图显示一个带有listview的对话框,其中包含我的数据库中的名称,但我不断收到StaleDataException.我知道这通常意味着我正在尝试使用来自闭合光标的数据但光标不会关闭,直到我得到所有数据所以我不明白为什么我得到这个 d = new Dialog(this);d.setContentView(R.layout.dialog_layout);d.setTitle("Select 我试图显示一个带有ListvIEw的对话框,其中包含我的数据库中的名称,但我不断收到StaleDataException.我知道这通常意味着我正在尝试使用来自闭合光标的数据但光标不会关闭,直到我得到所有数据所以我不明白为什么我得到这个
d = new Dialog(this);d.setContentVIEw(R.layout.dialog_layout);d.setTitle("Select Bowler");ListVIEw lv = (ListVIEw)d.findVIEwByID(R.ID.dialog_List);Cursor c = getContentResolver().query(    BowlersDB.CONTENT_URI,new String[] {        BowlersDB.ID,BowlersDB.FirsT_name,BowlersDB.LAST_name    },null,BowlersDB.LAST_name + " ColLATE LOCAliZED ASC");if (c.movetoFirst() && c != null) {    SimpleCursorAdapter adapter = new SimpleCursorAdapter(        this,R.layout.names_ListvIEw,c,new String[] {            BowlersDB.FirsT_name,BowlersDB.LAST_name        },new int[] {            R.ID.bListTextVIEw,R.ID.bListTextVIEw2        },0    );    lv.setAdapter(adapter);    lv.setonItemClickListener(new OnItemClickListener() {        @OverrIDe        public voID onItemClick(AdapterVIEw<?> arg0,VIEw v,int position,long ID) {            bowlerClickedID = ID;            updatename(ID);        }    });    d.show();}c.close();

错误

androID.database.StaleDataException:    Attempting to access a closed CursorWindow.    Most probable cause: cursor is deactivated prior to calling this method.   at androID.database.AbstractwindowedCursor.checkposition(AbstractwindowedCursor.java:139)   at androID.database.AbstractwindowedCursor.getString(AbstractwindowedCursor.java:50)   at androID.database.CursorWrapper.getString(CursorWrapper.java:114)   at androID.Widget.SimpleCursorAdapter.bindVIEw(SimpleCursorAdapter.java:150)   at androID.Widget.CursorAdapter.getVIEw(CursorAdapter.java:250)   at androID.Widget.AbsListVIEw.obtainVIEw(AbsListVIEw.java:2267)   at androID.Widget.ListVIEw.measureHeightOfChildren(ListVIEw.java:1244)   at androID.Widget.ListVIEw.onMeasure(ListVIEw.java:1156)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4814)   at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1390)   at androID.Widget.linearLayout.measureVertical(linearLayout.java:681)   at androID.Widget.linearLayout.onMeasure(linearLayout.java:574)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4814)   at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:310)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4814)   at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:310)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4814)   at androID.Widget.linearLayout.measureChildBeforeLayout(linearLayout.java:1390)   at androID.Widget.linearLayout.measureVertical(linearLayout.java:681)   at androID.Widget.linearLayout.onMeasure(linearLayout.java:574)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   at androID.vIEw.VIEwGroup.measureChilDWithmargins(VIEwGroup.java:4814)   at androID.Widget.FrameLayout.onMeasure(FrameLayout.java:310)   at com.androID.internal.policy.impl.PhoneWindow$DecorVIEw.onMeasure(PhoneWindow.java:2148)   at androID.vIEw.VIEw.measure(VIEw.java:15172)   ...

编辑:
如果我注释掉c.close()行,它工作正常,但我不能将光标打开,所以我该怎么办?

解决方法 在不再需要CursorAdapter之前,无法关闭光标.所以你可以在onDestroy()方法中关闭它:
@OverrIDepublic voID onDestroy() { super.onDestroy(); ListVIEw lv = (ListVIEw) d.findVIEwByID(R.ID.dialog_List); ((CursorAdapter) lv.getAdapter()).getCursor().close(); database.close();}
总结

以上是内存溢出为你收集整理的android – 带对话框的StaleDataException全部内容,希望文章能够帮你解决android – 带对话框的StaleDataException所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1137147.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存