【发布时间】:2020-10-30 08:34:37
【问题描述】:
我正在尝试从“Map<ArrayList<String>, Object>”中扩充数据
我将 Header 存储为ArrayList<String>,将子列表存储为Object。问题是我运行代码时它崩溃了。
这是我的调试控制台:
E/JavaBinder: !!! FAILED BINDER TRANSACTION !!!
E/AndroidRuntime: Error reporting crash
android.os.TransactionTooLargeException
at android.os.BinderProxy.transactNative(Native Method)
at android.os.BinderProxy.transact(Binder.java:496)
at android.app.ActivityManagerProxy.handleApplicationCrash(ActivityManagerNative.java:4164)
at com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException(RuntimeInit.java:89)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)
at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)
错误:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chonang.chonangclientlogin, PID: 12175
java.lang.StackOverflowError: stack size 8MB
at com.chonang.chonangclientlogin.listViewAdapter.TestExpandableView.getGroupId(TestExpandableView.java:65)
错误在65行指示
这是我的适配器代码:
public TestExpandableView(String allow, Map<ArrayList<String>, Object> headerListArrayList, String country, String state, String city, String tree, Context context) {
this.allow=allow;
this.country=country;
this.state=state;
this.city=city;
this.TREE=tree;
this.data=headerListArrayList;
this.context= context;
}
@Override
public int getGroupCount() {
return data.size();
}
@Override
public int getChildrenCount(int groupPosition) {
return (int) data.get(getChildrenCount(groupPosition));
}
@Override
public Object getGroup(int groupPosition) {
return groupPosition;
}
@Override
public Object getChild(int groupPosition, int childPosition) {
return data.get(getChild(groupPosition,childPosition)); // THE ERROR IS INDICATION HERE
}
@Override
public long getGroupId(int groupPosition) {
return (long) data.get(getGroupId(groupPosition));
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
@Override
public boolean hasStableIds() {
return false;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
String headerTitle = (String) data.get(getGroup(groupPosition));
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.expandable_view_header, null);
}
ExpandableListView mExpandableListView = (ExpandableListView) parent;
mExpandableListView.expandGroup(groupPosition,isExpanded);
TextView headerName = convertView.findViewById(R.id.headerName);
headerName.setText(headerTitle);
return convertView;
}
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
initializedData(convertView);
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.card_view, null);
}
ItemListProduct data;
data= (ItemListProduct) getChild(groupPosition,childPosition);
itemName.setText(String.valueOf(data.getITEM_NAME()));
return convertView;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return false;
}
private void initializedData(View convertView) {
itemView= convertView.findViewById(R.id.itemView);
itemName = convertView.findViewById(R.id.ListViewItemNameAdapter);
}
}
【问题讨论】:
-
您在没有退出的情况下递归调用相同的函数。通过从
getChild调用getChild,您只需耗尽内存,然后您的应用程序就会被系统杀死。getGroupId和getChildrenCount方法也会出现同样的问题。 Recursion in java. -
@JeneaVranceanu 好的,但是我使用的变量是 Map
, object> 并且存储在 object 中的值是一个 Array 对象。在这种情况下我将由谁来做? -
@JeneaVranceanu,你认为我的代码正确吗?如果是我想知道如何获得价值和位置。既然
Map<ArrayList<String>"here is the header", Object" here is the Value Stored in Array">怎么找回来??? -
获取对象的大小。
标签: android hashmap expandablelistview