Android: не удалось отследить исключение ClassCastException с помощью SimpleExpandableListAdapter - PullRequest
0 голосов
/ 12 мая 2011

Я получаю следующее исключение при запуске моей программы:

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, но какую ошибку я здесь ищу?

Пожалуйста, пожалуйста помоги.:)

С уважением, медуза

1 Ответ

0 голосов
/ 12 мая 2011

Закомментировав мою секцию изменения данных и сравнив ее с исходной реализацией данных, я обнаружил свою ошибку.Это было довольно просто.

//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);

Была ошибка копирования и вставки из-за изменения дочерних данных.

...