[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
On 16 окт, 20:10, Romain Guy romain...@google.com wrote: (it is a quote from sources ListView.java) and only in this case. Thus, if number of elements wasn't changed, everything is ok. Thanks, Sergey. If you modify the adapter without changing the number of items it can also be bad. It's just that ListView does not detect this case. Ok, Romain, this is clear. but what about performance? In example, we have the ListView that should be filled with the data from the server. When we will fill it on UI thread will it cause UI freezing if we have a lot of elements (several hundred)? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
There's no performance issue: you do all the work on a background thread and then you add everything in the adapter on the UI thread. A simple loop to add() several hundreds elements should not freeze the UI. On Oct 19, 2009 2:49 AM, Alexey goalstu...@gmail.com wrote: On 16 окт, 20:10, Romain Guy romain...@google.com wrote: (it is a quote from sources ListVi... Thanks, Sergey. If you modify the adapter without changing the number of items it can also be bad. It's just th... Ok, Romain, this is clear. but what about performance? In example, we have the ListView that should be filled with the data from the server. When we will fill it on UI thread will it cause UI freezing if we have a lot of elements (several hundred)? --~--~-~--~~~---~--~~ You received this message because you are sub... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Thanks, Romain, I will try... On 19 окт, 14:00, Romain Guy romain...@google.com wrote: There's no performance issue: you do all the work on a background thread and then you add everything in the adapter on the UI thread. A simple loop to add() several hundreds elements should not freeze the UI. On Oct 19, 2009 2:49 AM, Alexey goalstu...@gmail.com wrote: On 16 окт, 20:10, Romain Guy romain...@google.com wrote: (it is a quote from sources ListVi... Thanks, Sergey. If you modify the adapter without changing the number of items it can also be bad. It's just th... Ok, Romain, this is clear. but what about performance? In example, we have the ListView that should be filled with the data from the server. When we will fill it on UI thread will it cause UI freezing if we have a lot of elements (several hundred)? --~--~-~--~~~---~--~~ You received this message because you are sub... --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Alexey, ListView chashes in case of: if (mItemCount != mAdapter.getCount()) { throw new 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.); } (it is a quote from sources ListView.java) and only in this case. Thus, if number of elements wasn't changed, everything is ok. On 15 окт, 16:47, Alexey goalstu...@gmail.com wrote: Romain, one more question. Is this rule applicable for adding/removing elements from adapter (in other words - changing number of elements in ListView) or also when changing content of elements? On 15 окт, 16:31, Alexey goalstu...@gmail.com wrote: Romain, your answers are clear, but confusing. As I understood modifying adapter should be done in workerthreadand only notifyDataSetChanged in UIthread. Now as I see the concept is different, but what if we need to add several hundred items into adapter, won't UIthreadbe in freeze for this time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
(it is a quote from sources ListView.java) and only in this case. Thus, if number of elements wasn't changed, everything is ok. If you modify the adapter without changing the number of items it can also be bad. It's just that ListView does not detect this case. On 15 окт, 16:47, Alexey goalstu...@gmail.com wrote: Romain, one more question. Is this rule applicable for adding/removing elements from adapter (in other words - changing number of elements in ListView) or also when changing content of elements? On 15 окт, 16:31, Alexey goalstu...@gmail.com wrote: Romain, your answers are clear, but confusing. As I understood modifying adapter should be done in workerthreadand only notifyDataSetChanged in UIthread. Now as I see the concept is different, but what if we need to add several hundred items into adapter, won't UIthreadbe in freeze for this time? -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Romain, your answers are clear, but confusing. As I understood modifying adapter should be done in worker thread and only notifyDataSetChanged in UI thread. Now as I see the concept is different, but what if we need to add several hundred items into adapter, won't UI thread be in freeze for this time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Romain, one more question. Is this rule applicable for adding/removing elements from adapter (in other words - changing number of elements in ListView) or also when changing content of elements? On 15 окт, 16:31, Alexey goalstu...@gmail.com wrote: Romain, your answers are clear, but confusing. As I understood modifying adapter should be done in worker thread and only notifyDataSetChanged in UI thread. Now as I see the concept is different, but what if we need to add several hundred items into adapter, won't UI thread be in freeze for this time? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Same issue here! Thanks for the information! -Moto! On Oct 11, 3:11 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, Fantastic, thanks for the help! I've had customers contact me over the months about force closes that I can never get to the bottom of. This likely has fixed the lingering issues. Great news! Thanks, pawpaw17 On Oct 11, 2:08 pm, Romain Guy romain...@google.com wrote: In my background thread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. No, this is related to the use of threads. Even adding 1 element could cause the crash. You just cannot really predict the behavior. That's why this exception was added, to help you write your apps correctly. Otherwise your app would look like it's working except in some cases bad things would happen (crash in the UI toolkit, surprising behavior in the UI, etc.) How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in a background thread? Do we just do the database read in the background and then process the results from the cursors in the UI thread? That's a possibility. You could also just use a CursorAdapter. You could also use an AsyncTask and add new elements to the array using publishProgress() every X elements processed. Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
That's a possibility. You could also just use a CursorAdapter I had also this error, and I used SimpleCursorAdapter, that's why i think, it isn't solution of the problem. ccfrazier2, Try to frequently select items, while list is adding new elements, error may be repeated(may be not). ( if you do this, you'll be frequently call layoutChildren()) Sorry for my bad English. On 12 окт, 18:16, Moto medicalsou...@gmail.com wrote: Same issue here! Thanks for the information! -Moto! On Oct 11, 3:11 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, Fantastic, thanks for the help! I've had customers contact me over the months about force closes that I can never get to the bottom of. This likely has fixed the lingering issues. Great news! Thanks, pawpaw17 On Oct 11, 2:08 pm, Romain Guy romain...@google.com wrote: In mybackgroundthread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. No, this is related to the use of threads. Even adding 1 element could cause the crash. You just cannot really predict the behavior. That's why this exception was added, to help you write your apps correctly. Otherwise your app would look like it's working except in some cases bad things would happen (crash in the UI toolkit, surprising behavior in the UI, etc.) How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in abackgroundthread? Do we just do the database read in thebackgroundand then process the results from the cursors in the UI thread? That's a possibility. You could also just use a CursorAdapter. You could also use an AsyncTask and add new elements to the array using publishProgress() every X elements processed. Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line:
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
That's a possibility. You could also just use a CursorAdapter I also had this error, and I used SimpleCursorAdapter, that's why i think, it isn't solution of the problem. ccfrazier2, Try to frequently select items, while list is adding new elements, error may be repeated(may be not). ( if you do this, you'll be frequently call layoutChildren()) Sorry for my bad English. On 12 окт, 18:16, Moto medicalsou...@gmail.com wrote: Same issue here! Thanks for the information! -Moto! On Oct 11, 3:11 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, Fantastic, thanks for the help! I've had customers contact me over the months about force closes that I can never get to the bottom of. This likely has fixed the lingering issues. Great news! Thanks, pawpaw17 On Oct 11, 2:08 pm, Romain Guy romain...@google.com wrote: In mybackgroundthread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. No, this is related to the use of threads. Even adding 1 element could cause the crash. You just cannot really predict the behavior. That's why this exception was added, to help you write your apps correctly. Otherwise your app would look like it's working except in some cases bad things would happen (crash in the UI toolkit, surprising behavior in the UI, etc.) How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in abackgroundthread? Do we just do the database read in thebackgroundand then process the results from the cursors in the UI thread? That's a possibility. You could also just use a CursorAdapter. You could also use an AsyncTask and add new elements to the array using publishProgress() every X elements processed. Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line:
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
It's not a bug, it's a message that was added to notify app developers of applications that are doing the wrong thing. I'm sure my adapter mods are not in the UI thread. Which is exactly the problem. -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Romain, thanks for confirming that this message is new in 1.6. Actually, I mean to write I'm sure my adapter mods are IN the UI thread, not the background thread. Anything else that can cause this? If I step through the code in the debugger I don't get the exception, but I I run without stepping I do. Also, when I run the phone on the app, I can get it to work 3 or 4 times, and then eventually I'll get the force close. Can anything else cause this? Here's my code in the background thread: public void run(){ int i = 0; lsDb.openDataBase(); rescursor = lsDb.Search(); if (rescursor.getCount() 0){ id_index = rescursor.getColumnIndex(_id); name_index = rescursor.getColumnIndex(Name); calories_index = rescursor.getColumnIndex(Calories); extra_index = rescursor.getColumnIndex(sodium); } if (rescursor.moveToFirst()){ do { int id = rescursor.getInt(id_index); String name = rescursor.getString(name_index); int calories = rescursor.getInt(calories_index); double extra= rescursor.getDouble(extra_index); // add to array list myArrayList.add(i, new CalStats(name, extra, calories)); i++; } while (rescursor.moveToNext()); } rescursor.close(); lsDb.close(); hh.post(postdoSearchDatabase); } The post at the end is to a handler. I **do** modify the adapter in the run method there. On Oct 11, 1:36 am, Romain Guy romain...@google.com wrote: It's not a bug, it's a message that was added to notify app developers of applications that are doing the wrong thing. I'm sure my adapter mods are not in the UI thread. Which is exactly the problem. -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
When you get the error, can you see from the traceback which thread you are in? -- RichardC On Oct 11, 4:06 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, thanks for confirming that this message is new in 1.6. Actually, I mean to write I'm sure my adapter mods are IN the UI thread, not the background thread. Anything else that can cause this? If I step through the code in the debugger I don't get the exception, but I I run without stepping I do. Also, when I run the phone on the app, I can get it to work 3 or 4 times, and then eventually I'll get the force close. Can anything else cause this? Here's my code in the background thread: public void run(){ int i = 0; lsDb.openDataBase(); rescursor = lsDb.Search(); if (rescursor.getCount() 0){ id_index = rescursor.getColumnIndex(_id); name_index = rescursor.getColumnIndex(Name); calories_index = rescursor.getColumnIndex(Calories); extra_index = rescursor.getColumnIndex(sodium); } if (rescursor.moveToFirst()){ do { int id = rescursor.getInt(id_index); String name = rescursor.getString(name_index); int calories = rescursor.getInt(calories_index); double extra= rescursor.getDouble(extra_index); // add to array list myArrayList.add(i, new CalStats(name, extra, calories)); i++; } while (rescursor.moveToNext()); } rescursor.close(); lsDb.close(); hh.post(postdoSearchDatabase); } The post at the end is to a handler. I **do** modify the adapter in the run method there. On Oct 11, 1:36 am, Romain Guy romain...@google.com wrote: It's not a bug, it's a message that was added to notify app developers of applications that are doing the wrong thing. I'm sure my adapter mods are not in the UI thread. Which is exactly the problem. -- Romain Guy Android framework engineer romain...@android.com Note: please don't send private questions to me, as I don't have time to provide private support. All such questions should be posted on public forums, where I and others can see and answer them --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed in a routine that gets called from my handler, ie I post at the end of the run method of the worker thread so I can notify the array adapter from the UI thread. private void fillList(){ Collections.sort(myArrayList); // aa is an arrayAdapter aa.notifyDataSetChanged(); } Thanks for any thoughts you guys have on this. Very best, pawpaw17 On Oct 11, 10:20 am, RichardC richard.crit...@googlemail.com wrote: When you get the error, can you see from the traceback which thread you are in? -- RichardC On Oct 11, 4:06 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, thanks for confirming that this message is new in 1.6. Actually, I mean to write I'm sure my adapter mods are IN the UI thread, not the background thread. Anything else that can cause this? If I step through the code in the debugger I don't get the exception, but I I run without stepping I do. Also, when I run the phone on the app, I can get it to work 3 or 4 times, and then eventually I'll get the force close. Can anything else cause this? Here's my code in the background thread: public void run(){ int i = 0; lsDb.openDataBase(); rescursor = lsDb.Search(); if (rescursor.getCount() 0){ id_index = rescursor.getColumnIndex(_id); name_index = rescursor.getColumnIndex(Name); calories_index = rescursor.getColumnIndex(Calories); extra_index = rescursor.getColumnIndex(sodium); } if (rescursor.moveToFirst()){ do { int id = rescursor.getInt(id_index); String name = rescursor.getString(name_index); int calories = rescursor.getInt(calories_index); double extra= rescursor.getDouble(extra_index); // add to array list myArrayList.add(i, new CalStats(name, extra, calories)); i++; } while (rescursor.moveToNext()); } rescursor.close(); lsDb.close(); hh.post(postdoSearchDatabase); } The post
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
-- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed in a routine that gets called from my handler, ie I post at the end of the run method of the worker thread so I can notify the array adapter from the UI thread. private void fillList(){ Collections.sort(myArrayList); // aa is an arrayAdapter aa.notifyDataSetChanged(); } Thanks for any thoughts you guys have on this. Very best, pawpaw17 On Oct 11, 10:20 am, RichardC richard.crit...@googlemail.com wrote: When you get the error, can you see from the traceback which thread you are in? -- RichardC On Oct 11, 4:06 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, thanks for confirming that this message is new in 1.6. Actually, I mean to write I'm sure my adapter mods are IN the UI thread, not the background thread. Anything else that can cause this? If I step through the code in the debugger I don't get the exception, but I I run without stepping I do. Also, when I run the phone on the app, I can get it to work 3 or 4 times, and then eventually I'll get the force close. Can anything else cause this? Here's my code in the background thread: public void run(){ int i = 0; lsDb.openDataBase(); rescursor = lsDb.Search(); if (rescursor.getCount() 0){ id_index = rescursor.getColumnIndex(_id); name_index = rescursor.getColumnIndex(Name); calories_index = rescursor.getColumnIndex(Calories); extra_index = rescursor.getColumnIndex(sodium); } if (rescursor.moveToFirst()){ do { int id = rescursor.getInt(id_index); String name = rescursor.getString(name_index); int calories = rescursor.getInt(calories_index); double extra= rescursor.getDouble(extra_index); // add to array list myArrayList.add(i, new CalStats(name, extra, calories));
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Thanks so much for the replies. Maybe I've been doing this wrong all along, I have 6 activites that use this same methodology, but YES, I guess this is the array used by the adapter (code below shows that is is). In my background thread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in a background thread? Do we just do the database read in the background and then process the results from the cursors in the UI thread? Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed in a routine that gets called from my handler, ie I post at the end of the run method of the worker thread so I can notify the array adapter from the UI thread. private void fillList(){ Collections.sort(myArrayList); // aa is an arrayAdapter aa.notifyDataSetChanged(); } Thanks for any thoughts you guys have on this. Very best, pawpaw17 On Oct 11, 10:20 am, RichardC richard.crit...@googlemail.com wrote: When you get the error, can you see from the traceback which thread you are in? -- RichardC On Oct 11, 4:06 pm, ccfrazier2 georgefraz...@yahoo.com wrote: Romain, thanks for confirming that this message is new in 1.6. Actually, I mean to write I'm sure my adapter mods are IN the UI thread, not the background thread. Anything else that can cause this? If I step through the code in the debugger I
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
ccfrazier2 wrote: Thanks so much for the replies. Maybe I've been doing this wrong all along, I have 6 activites that use this same methodology, but YES, I guess this is the array used by the adapter (code below shows that is is). In my background thread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. It is background thread related. Do not modify the underlying ArrayList from a background thread. How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in a background thread? Do we just do the database read in the background and then process the results from the cursors in the UI thread? That is one possibility. Or, dump the ArrayAdapter/ArrayList and use a CursorAdapter. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://twitter.com/commonsguy Need Android talent? Ask on HADO! http://wiki.andmob.org/hado --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~--~~~~--~~--~--~---
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
In my background thread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. No, this is related to the use of threads. Even adding 1 element could cause the crash. You just cannot really predict the behavior. That's why this exception was added, to help you write your apps correctly. Otherwise your app would look like it's working except in some cases bad things would happen (crash in the UI toolkit, surprising behavior in the UI, etc.) How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in a background thread? Do we just do the database read in the background and then process the results from the cursors in the UI thread? That's a possibility. You could also just use a CursorAdapter. You could also use an AsyncTask and add new elements to the array using publishProgress() every X elements processed. Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed in a routine that gets called from my handler, ie I post at the end of the run method of the worker thread so I can notify the array adapter from the UI thread. private void fillList(){ Collections.sort(myArrayList); // aa is an arrayAdapter aa.notifyDataSetChanged(); } Thanks for any thoughts you guys have on this. Very best, pawpaw17 On Oct 11, 10:20 am, RichardC richard.crit...@googlemail.com wrote: When you get the error, can you see from the traceback which thread you are in?
[android-developers] Re: ListView/Adapter Crash in 1.6 only: illegalStateException. 1.6 bug?
Romain, Fantastic, thanks for the help! I've had customers contact me over the months about force closes that I can never get to the bottom of. This likely has fixed the lingering issues. Great news! Thanks, pawpaw17 On Oct 11, 2:08 pm, Romain Guy romain...@google.com wrote: In my background thread if I add 100 elements to the array, everything works great. If I add more than 300 though I get the crash. Is this capacity related. No, this is related to the use of threads. Even adding 1 element could cause the crash. You just cannot really predict the behavior. That's why this exception was added, to help you write your apps correctly. Otherwise your app would look like it's working except in some cases bad things would happen (crash in the UI toolkit, surprising behavior in the UI, etc.) How are we supposed to populate an array list associated with an array adapter when we are grabbing stuff out of the database in a background thread? Do we just do the database read in the background and then process the results from the cursors in the UI thread? That's a possibility. You could also just use a CursorAdapter. You could also use an AsyncTask and add new elements to the array using publishProgress() every X elements processed. Very best regards pawpaw17 in OnCreate... if (aa == null){ aa = new myArrayAdapter(this); } lList.setAdapter(aa); Thread thread = new Thread(null, doSearchDatabase, Background); thread.start(); } myArrayAdapter aa = null; final ArrayListMyStats myArrayList = new ArrayListMyStats(); class myArrayAdapter extends ArrayAdapter { Activity context; myArrayAdapter(Activity context) { super(context, R.layout.caloriesrow, myArrayList); this.context=context; } On Oct 11, 1:36 pm, Romain Guy romain...@google.com wrote: -- myArrayList.add(i, new CalStats(name, extra, calories)); if that's the array list used by your adapter then you are modifying it outside of the UI thread. On Sun, Oct 11, 2009 at 11:07 AM, ccfrazier2 georgefraz...@yahoo.com wrote: Yeah, it's the main thread of my app, here's the stack: myApp [Android Application] myApp [Android Application] DalvikVM[localhost:8613] Thread [3 main] (Suspended (exception IllegalStateException)) Thread [15 Binder Thread #3] (Running) Thread [13 Binder Thread #2] (Running) Thread [11 Binder Thread #1] (Running) Thread [3 main] (Suspended (exception IllegalStateException)) ListView.layoutChildren() line: 1596 ListView(AbsListView).onLayout(boolean, int, int, int, int) line: 1112 ListView(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 FrameLayout.onLayout(boolean, int, int, int, int) line: 333 FrameLayout(View).layout(int, int, int, int) line: 6569 LinearLayout.setChildFrame(View, int, int, int, int) line: 1119 LinearLayout.layoutVertical() line: 998 LinearLayout.onLayout(boolean, int, int, int, int) line: 918 LinearLayout(View).layout(int, int, int, int) line: 6569 PhoneWindow$DecorView(FrameLayout).onLayout(boolean, int, int, int, int) line: 333 PhoneWindow$DecorView(View).layout(int, int, int, int) line: 6569 ViewRoot.performTraversals() line: 979 ViewRoot.handleMessage(Message) line: 1613 ViewRoot(Handler).dispatchMessage(Message) line: 99 Looper.loop() line: 123 ActivityThread.main(String[]) line: 4203 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 521 ZygoteInit$MethodAndArgsCaller.run() line: 791 ZygoteInit.main(String[]) line: 549 NativeStart.main(String[]) line: not available [native method] None of my code in this stack. Any thoughts on how to track this down? I'm sure I'm doing something wrong - but it was never a problem as far as I knew running with 1.5. I spawn a thread at the end of OnCreate in my Activity that reads values from a database and populates the listView. The database reading is done in the worker thread, and I sort the list and tell the arrayadapter to notify tht the list has changed in a routine that gets called from my handler, ie I post at the end of the run method of the worker thread so I can notify the array adapter from the UI thread. private void fillList(){