运行我的程序时出现以下异常:
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.getView(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)
我自己的代码无处可见,我尝试调试,但错误发生在我的方法之间。我真的不知道该怎么找原因!
事实上,我正在改变SimpleExpandableListAdapter背后的数据,但我在这里寻找什么样的错误?
拜托,请帮忙。 :)
亲切的问候, 水母
答案 0 :(得分:0)
通过注释掉我的数据更改部分并将其与数据的原始实例化进行比较,我发现了我的错误。这很简单。
//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);
来自子数据的复制粘贴错误。