listView 出现 IllegalStateException - 在打开屏幕之前打开浏览器。

发布于 2024-12-13 04:50:11 字数 3431 浏览 1 评论 0原文

我正在开发一个应用程序,如果用户登录,该应用程序将跳过屏幕......同时在返回 void 的异步任务中......检查应用程序的升级以及是否有它通常会打开浏览器并下载文件......并且在主线程中,如果应用程序已经存储了登录凭据,那么它会转到另一个类/屏幕。通常有一个列表视图...列表是一个接一个地填充的记录...但有时我会遇到应用程序崩溃,我该如何解决这个问题...以及

PS。对列表视图的更新是从 asyncTask 触发的,该异步任务通常调用主线程中的函数来更新视图,...

    11-01 12:30:27.038: WARN/dalvikvm(10067): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067): FATAL EXCEPTION: main
11-01 12:30:27.038: ERROR/AndroidRuntime(10067): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class biz.graphight.graphight.CallSheetTab$CustomAdapter)]
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.ListView.layoutChildren(ListView.java:1567)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.AbsListView.onLayout(AbsListView.java:1263)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.os.Looper.loop(Looper.java:123)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.app.ActivityThread.main(ActivityThread.java:4628)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at java.lang.reflect.Method.invokeNative(Native Method)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at java.lang.reflect.Method.invoke(Method.java:521)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:879)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:637)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at dalvik.system.NativeStart.main(Native Method)

任何想法...请...

I am working on an application that would be working on the just skips a screen if the user is logged in .... and in the meanwhile in a asynctask which returns a void... check for a upgrade for the applicaiton and if there is any it would usually open a browser and download a file... and in the main thread if applicaiton has login credentials stored already then it goes to another class/screen. which usually has a listview.... The list is populated one after the another record .... but in between sometimes i get an applicaiton crash for the applicaiton how do i tackle this... and

PS. the update to the listview is being triggered from a asyncTask that usually calls a function in the main thread to update the view,...

    11-01 12:30:27.038: WARN/dalvikvm(10067): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067): FATAL EXCEPTION: main
11-01 12:30:27.038: ERROR/AndroidRuntime(10067): java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but only from the UI thread. [in ListView(16908298, class android.widget.ListView) with Adapter(class biz.graphight.graphight.CallSheetTab$CustomAdapter)]
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.ListView.layoutChildren(ListView.java:1567)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.AbsListView.onLayout(AbsListView.java:1263)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.RelativeLayout.onLayout(RelativeLayout.java:909)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1249)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1125)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1042)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.View.layout(View.java:7035)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1045)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.os.Handler.dispatchMessage(Handler.java:99)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.os.Looper.loop(Looper.java:123)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at android.app.ActivityThread.main(ActivityThread.java:4628)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at java.lang.reflect.Method.invokeNative(Native Method)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at java.lang.reflect.Method.invoke(Method.java:521)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:879)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:637)
11-01 12:30:27.038: ERROR/AndroidRuntime(10067):     at dalvik.system.NativeStart.main(Native Method)

Any ideas... please...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冰火雁神 2024-12-20 04:50:11

确保您已获取 doInBackground() 内的所有列表项,然后更新 onPostExecute() 方法内的列表视图。

如果您想更新获取项目并在下载时显示项目的进度,则必须更新 runOnUIThread()

例如:

/* Update UI */
myActivity.this.runOnUiThread(new Runnable() {
   @Override
   public void run() {
        /* Do UI update for activity A */;
   }
 });

相关关于 runOnUiThread 的问题

Make sure you have fetched all the list items inside the doInBackground() and then updated the listview inside the onPostExecute() method.

If you want to update the progress of fetching item and displaying item as and when it is downloaded then you have to update the listview inside the runOnUIThread()

For example:

/* Update UI */
myActivity.this.runOnUiThread(new Runnable() {
   @Override
   public void run() {
        /* Do UI update for activity A */;
   }
 });

Related: Question about runOnUiThread

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文