Hi! I'm trying to get my first Android app stable enough for the
marketplace, and I've hit a brick wall with one exception that I don't
understand. Probably I'm doing something stupid, but I can't tell
what, and after several hours googling and experimenting, I thought
I'd see if I can get some help. My Activity extends ListActivity, and
the parts I think are most important are extracted below:
GroupedListAdapter is a simple class that extends BasedAdapter to
provide headings for sections of the list (not unlike the Fancy
ListView tutorials that are floating around).
I create this in onCreate, and it works fine. Inside onListItemClick,
I do some actions which will create a different set of list contents.
I "clear" the adapter, which empties the contents, and call reload,
which repopulates it. Then I call notifyDataSetChanged.
Most often, this seems to work, but also fairly often, I get the
exception following the code snippets below - this seems to indicate
the ListView is not in sync with my changes. Lately this crash
happens 100% of the time under the simulator.
Any ideas where I should be looking?
Thanks in advance for any tips!
Wendell
public void onCreate(Bundle savedInstanceState) {
...
adapter = new GroupedListAdapter(this, R.layout.list_header);
reload();
setListAdapter(adapter);
}
void reload() {
for (int i = 0; i < models.titles.size(); ++i) {
String title = models.titles.get(i);
List<Option> options = models.sections.get(i);
adapter.addSection(title, new FancyAdapter(this, options));
}
}
public void onListItemClick(ListView parent, View v,
int position, long id) {
adapter.clear();
reload();
adapter.notifyDataSetChanged();
}
Thread [<3> main] (Suspended (exception
ArrayIndexOutOfBoundsException))
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]
nged();
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en