开发者

Android: not able to trace down a ClassCastException with SimpleExpandableListAdapter

I get the following exception running my program:

05-12 08:29:06.907: ERROR/AndroidRuntime(460): FATAL EXCEPTION: main
05-12 08:29:06.907: ERROR/AndroidRuntime(460): java.lang.ClassCastException: java.util.ArrayList
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.SimpleExpandableListAdapter.getGroupView(SimpleExpandableListAdapter.java:278)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.ExpandableListConnector.getVie开发者_Python百科w(ExpandableListConnector.java:445)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.AbsListView.obtainView(AbsListView.java:1294)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.ListView.onMeasure(ListView.java:1109)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:578)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:362)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.View.measure(View.java:8171)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewRoot.performTraversals(ViewRoot.java:801)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.os.Looper.loop(Looper.java:123)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at java.lang.reflect.Method.invokeNative(Native Method)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at java.lang.reflect.Method.invoke(Method.java:521)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 08:29:06.907: ERROR/AndroidRuntime(460):     at dalvik.system.NativeStart.main(Native Method)

My own code nowhere shows up and I tried debugging, but the error occurs between my methods. I really don't know how to look for the reason!

I am, in fact, changing the data behind the SimpleExpandableListAdapter, but what kind of error am I looking for here?

Please, please help. :)

Kind regards, jellyfish


By commenting out my data change section and comparing it to the original instantiation of the data I found my error. It was fairly simple.

//that's how I canged my group data
List newGroups = new ArrayList();

for(int i = 0; i < groups.size(); ++i)
{
    String savedGroupName = (String) ((HashMap) groups.get(i)).get(groupName);
    HashMap groupContent = new HashMap();
    groupContent.put(groupName, savedGroupName);
    groupContent.put(groupRate, getString(R.string.newstring));
    newGroups.add(groupContent);
}

//but instead of using  
groups = newGroups;

//I had this:
groups.set(somePosition, newGroups);

Was a copy-and-paste error from the child data change.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜