>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 ArrayList<MyStats> myArrayList = new ArrayList<MyStats>(); > > > > > 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 > > > >> > thelistView. 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 thebackgroundthread". 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 thebackgroundthread: > > > > >> >> > 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 > > ... > > продолжение » --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---