我不明白为什么我的onChildClick方法中的可扩展列表视图中出现致命异常

时间:2017-01-11 09:54:40

标签: java android expandablelistview expandablelistadapter

我有一个可扩展的列表视图但是当我展开它并点击该子时我收到的错误是

  

致命的例外:主要                                                                                    处理:com.claritech.simsentinelmobile,PID:22606                                                                                    java.lang.ClassCastException:android.widget.ExpandableListConnector   无法转换为com.xera.deviceinsight.home.ExpandableListAdapter

这是抛出错误的行

 ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();

这是我尝试使用适配器检索对象的整个方法(使用改造从服务器中点击的子项的详细信息)

 private void load(View view)
   {

      expListView = (ExpandableListView) view.findViewById(R.id.lvExp);
      prepareListData();
      listAdapter = new ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild);
      expListView.setAdapter(listAdapter);
      expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
         @Override
         public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {

            System.err.println("child clicked");
            Toast.makeText(getActivity(), "child clicked", Toast.LENGTH_SHORT).show();
            EventBus.getDefault().post(new ItemClickedEvent(SensorInformationChildFragment.TAB_CALL));
            //ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
            ExpandableListAdapter adapter = (ExpandableListAdapter)parent.getAdapter();
            OrganisationDeviceSensorsResult d = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition,  childPosition);
            d.SensorID = d.SensorID;
            OrganisationDeviceSensorsResult deviceSensor = (OrganisationDeviceSensorsResult) adapter.getChild(groupPosition , childPosition);
            Object contact = adapter.getChild(groupPosition , childPosition);
           // OrganisationDeviceSensorsResult contact = listDataChild.get(groupPosition).getContacts().get(childPosition);
            //sensorID = deviceSensor.SensorID;
            //sensorID = contact.equals()

            ReportingGroup.get(childPosition);

            return true;
         }
      });
   } 

这是日志

01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile D/dalvikvm: threadid=1: detach (group=0x41816ce0)
01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x41816ce0)
01-11 11:42:30.328 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: uncaught exception occurred
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err: java.lang.ClassCastException: android.widget.ExpandableListConnector cannot be cast to com.xera.deviceinsight.home.ExpandableListAdapter
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err:     at com.xera.deviceinsight.home.CostCentreListFragment$1.onChildClick(CostCentreListFragment.java:88)
01-11 11:42:30.329 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:712)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:651)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
01-11 11:42:30.330 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.widget.AbsListView$3.run(AbsListView.java:3865)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.os.Handler.handleCallback(Handler.java:808)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:103)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.os.Looper.loop(Looper.java:193)
01-11 11:42:30.331 22606-22606/com.claritech.simsentinelmobile W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:5299)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err:     at java.lang.reflect.Method.invokeNative(Native Method)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err:     at java.lang.reflect.Method.invoke(Method.java:515)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
01-11 11:42:30.332 22606-22606/com.claritech.simsentinelmobile W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
01-11 11:42:30.333 22606-22606/com.claritech.simsentinelmobile W/System.err:     at dalvik.system.NativeStart.main(Native Method)
01-11 11:42:30.333 22606-22606/com.claritech.simsentinelmobile W/dalvikvm: threadid=1: calling UncaughtExceptionHandler
01-11 11:42:30.335 22606-22606/com.claritech.simsentinelmobile E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                 Process: com.claritech.simsentinelmobile, PID: 22606
                                                                                 java.lang.ClassCastException: android.widget.ExpandableListConnector cannot be cast to com.xera.deviceinsight.home.ExpandableListAdapter
                                                                                     at com.xera.deviceinsight.home.CostCentreListFragment$1.onChildClick(CostCentreListFragment.java:88)
                                                                                     at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:712)
                                                                                     at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:651)
                                                                                     at android.widget.AbsListView$PerformClick.run(AbsListView.java:3014)
                                                                                     at android.widget.AbsListView$3.run(AbsListView.java:3865)
                                                                                     at android.os.Handler.handleCallback(Handler.java:808)
                                                                                     at android.os.Handler.dispatchMessage(Handler.java:103)
                                                                                     at android.os.Looper.loop(Looper.java:193)
                                                                                     at android.app.ActivityThread.main(ActivityThread.java:5299)
                                                                                     at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                     at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
                                                                                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
                                                                                     at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:1)

尝试在以下语句中使用完全限定的类名,即 -

listAdapter = new com.xera.deviceinsight.home.ExpandableListAdapter(this.getActivity(), listDataHeader, listDataChild);