gpt4 book ai didi

java - 我不明白为什么我的可扩展 ListView 的 onChildClick 方法出现致命异常

转载 作者:行者123 更新时间:2023-11-30 00:47:16 25 4
gpt4 key购买 nike

我有一个可扩展的 ListView ,但是当我展开它并单击子项时,我收到一条错误消息

FATAL EXCEPTION: main Process: com.claritech.simsentinelmobile, PID: 22606 java.lang.ClassCastException: android.widget.ExpandableListConnector cannot be cast to 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)

最佳答案

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

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

关于java - 我不明白为什么我的可扩展 ListView 的 onChildClick 方法出现致命异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com