Merge Adapter and Fancy List Problem

146 views
Skip to first unread message

Dirtknap

unread,
Jan 5, 2010, 1:27:44 AM1/5/10
to cw-android
First off, thanks in advance to any help anyone can provide me, and
apologize if I'm coding over my head :)

I am working on a project that uses a dynamically created list view
that builds off of the Self Wrapper Demo from the Busy Coders Guide
Fancy List section. I also would like to use this with the Merge
Adapter. My project was giving me fits, so I boiled it down to just
the tutorial and the Merge adapter and found that it still has the
same problem. What I have found is that when "label.setText(getModel
(position));" is called after inflating the Layout, it envokes:

private String getModel(int position) {
return(((IconicAdapter)getListAdapter()).getItem(position));
}

and the LogCat spits out the following error:

"ERROR/AndroidRuntime(713): Uncaught handler: thread main exiting due
to uncaught exception"

I'm not sure where to begin to resolve this and any advice or
direction would be appreciated. Am I misusing the MergeAdapter?

Mark Murphy

unread,
Jan 5, 2010, 6:52:16 AM1/5/10
to cw-an...@googlegroups.com

Two things come to mind:

1. I'm removing the SelfWrapper sample in the next edition of the book,
due to complaints from the core Android team that I'm misusing the new
setTag()/getTag() API.

2. Are you sure there isn't a "Caused by" stanza of your Java stack trace
below the line you quoted, that gives you the root cause of the exception?

In terms of misusing the MergeAdapter, that is hard to say from what you
have described. For the pattern I think you are trying to achieve, you
would want the MergeAdapter to hold 1+ IconicAdapters (or other adapters),
and for your ListView to hold the MergeAdapter.

--
Mark Murphy (a Commons Guy)
http://commonsware.com
Android App Developer Books: http://commonsware.com/books.html


Dirtknap

unread,
Jan 5, 2010, 11:30:35 AM1/5/10
to cw-android

> Mark Murphy (a Commons Guy)http://commonsware.com


> Android App Developer Books:http://commonsware.com/books.html

Here is the rest of the exception message:


ERROR/AndroidRuntime(713): Uncaught handler: thread main exiting due
to uncaught exception

ERROR/AndroidRuntime(713): java.lang.ClassCastException:
com.commonsware.android.fancylists.eight.MergeAdapter
ERROR/AndroidRuntime(713): at
com.commonsware.android.fancylists.eight.SelfWrapperDemo.getModel
(SelfWrapperDemo.java:49)
ERROR/AndroidRuntime(713): at
com.commonsware.android.fancylists.eight.SelfWrapperDemo.access$0
(SelfWrapperDemo.java:48)
ERROR/AndroidRuntime(713): at
com.commonsware.android.fancylists.eight.SelfWrapperDemo
$IconicAdapter.getView(SelfWrapperDemo.java:77)
ERROR/AndroidRuntime(713): at
com.commonsware.android.fancylists.eight.MergeAdapter.getView
(MergeAdapter.java:196)
ERROR/AndroidRuntime(713): at android.widget.AbsListView.obtainView
(AbsListView.java:1273)
ERROR/AndroidRuntime(713): at
android.widget.ListView.makeAndAddView(ListView.java:1658)
ERROR/AndroidRuntime(713): at android.widget.ListView.fillDown
(ListView.java:637)
ERROR/AndroidRuntime(713): at android.widget.ListView.fillFromTop
(ListView.java:694)
ERROR/AndroidRuntime(713): at
android.widget.ListView.layoutChildren(ListView.java:1516)
ERROR/AndroidRuntime(713): at android.widget.AbsListView.onLayout
(AbsListView.java:1112)
ERROR/AndroidRuntime(713): at android.view.View.layout(View.java:
6569)
ERROR/AndroidRuntime(713): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
ERROR/AndroidRuntime(713): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
ERROR/AndroidRuntime(713): at android.widget.LinearLayout.onLayout
(LinearLayout.java:918)
ERROR/AndroidRuntime(713): at android.view.View.layout(View.java:
6569)
ERROR/AndroidRuntime(713): at android.widget.FrameLayout.onLayout
(FrameLayout.java:333)
ERROR/AndroidRuntime(713): at android.view.View.layout(View.java:
6569)
ERROR/AndroidRuntime(713): at
android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
ERROR/AndroidRuntime(713): at
android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
ERROR/AndroidRuntime(713): at android.widget.LinearLayout.onLayout
(LinearLayout.java:918)
ERROR/AndroidRuntime(713): at android.view.View.layout(View.java:
6569)
ERROR/AndroidRuntime(713): at android.widget.FrameLayout.onLayout
(FrameLayout.java:333)
ERROR/AndroidRuntime(713): at android.view.View.layout(View.java:
6569)
ERROR/AndroidRuntime(713): at
android.view.ViewRoot.performTraversals(ViewRoot.java:979)
ERROR/AndroidRuntime(713): at android.view.ViewRoot.handleMessage
(ViewRoot.java:1613)
ERROR/AndroidRuntime(713): at android.os.Handler.dispatchMessage
(Handler.java:99)
ERROR/AndroidRuntime(713): at android.os.Looper.loop(Looper.java:
123)
ERROR/AndroidRuntime(713): at android.app.ActivityThread.main
(ActivityThread.java:4203)
ERROR/AndroidRuntime(713): at java.lang.reflect.Method.invokeNative
(Native Method)
ERROR/AndroidRuntime(713): at java.lang.reflect.Method.invoke
(Method.java:521)
ERROR/AndroidRuntime(713): at com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
ERROR/AndroidRuntime(713): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
ERROR/AndroidRuntime(713): at dalvik.system.NativeStart.main
(Native Method)

And as for the code it is just the code form the download for the
SelfWrapper Demo with the following added (and the MergeAdapter
Class):

MergeAdapter adapter = new MergeAdapter();
adapter.addAdapter(new IconicAdapter());
setListAdapter(adapter);

Again, I apologize if I'm out of my depth, but I'm just not sure where
to go with this. It seems as if what is returning from getModel isn't
a String and that's why it is throwing the ClassCastException? Or is
it with the (IconicAdapter)getListAdapter()? Since it works without
the Merge Adapter, I keep coming back to that maybe I just really
don't understand how the Merge Adapter works. I appreciate the
assistance.

Mark Murphy

unread,
Jan 5, 2010, 9:05:41 PM1/5/10
to cw-an...@googlegroups.com
> Here is the rest of the exception message:
> ERROR/AndroidRuntime(713): Uncaught handler: thread main exiting due
> to uncaught exception
> ERROR/AndroidRuntime(713): java.lang.ClassCastException:
> com.commonsware.android.fancylists.eight.MergeAdapter
> ERROR/AndroidRuntime(713): at
> com.commonsware.android.fancylists.eight.SelfWrapperDemo.getModel
> (SelfWrapperDemo.java:49)

Look at line 49 in SelfWrapperDemo. You will find that you are casting
your MergeAdapter into something incompatible.

Dirtknap

unread,
Jan 5, 2010, 9:22:37 PM1/5/10
to cw-android
Awesome. Thanks, Mark. I was misunderstanding the MergeAdapter. I
was still trying to find the model by position in the adapter I fed
into the MergeAdapter, instead of getting it directly from the
MergeAdapter itself.
Reply all
Reply to author
Forward
0 new messages