Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

反馈一个关以json生成列表的问题 #301

Open
taood opened this issue Nov 9, 2022 · 1 comment
Open

反馈一个关以json生成列表的问题 #301

taood opened this issue Nov 9, 2022 · 1 comment

Comments

@taood
Copy link

taood commented Nov 9, 2022

在使用json 转表格时,使用表格的 smarTable.setSortColumn 排序功能 会报错,日志为:
E/AndroidRuntime: FATAL EXCEPTION: Thread-13
Process: com.example.shanxidemo, PID: 27579
com.bin.david.form.exception.TableException: NoSuchFieldException :Please check whether field name is correct!
at com.bin.david.form.core.TableParser$1.compare(TableParser.java:227)
at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351)
at java.util.TimSort.sort(TimSort.java:216)
at java.util.Arrays.sort(Arrays.java:1523)
at java.util.Collections.sort(Collections.java:238)
at com.bin.david.form.core.TableParser.sort(TableParser.java:196)
at com.bin.david.form.core.TableParser.parse(TableParser.java:42)
at com.example.shanxidemo.phaseIi.view.SmartTable$1.run(SmartTable.java:238)
at java.lang.Thread.run(Thread.java:761)

@taood
Copy link
Author

taood commented Nov 9, 2022

经过,我的不懈努力发现问题出现在
public T getData(Object o) throws NoSuchFieldException, IllegalAccessException {
String[] fieldNames = fieldName.split("\.");
if (fieldNames.length >0) {
Object child = o;
for (int i = 0; i < fieldNames.length; i++) {
if (child == null) {
return null;
}
Class childClazz = child.getClass();
Field childField = childClazz.getDeclaredField(fieldNames[i]);
if (childField == null) {
return null;
}
childField.setAccessible(true);
if (i == fieldNames.length - 1) {
return (T) childField.get(child);

            } else {
                child = childField.get(child);
            }
        }

    }
    return  null;
}

这里 因为你使用json 是转换成linkHasMap 而这边使用 泛型获取名称 肯定会报错,所以我在 TableParser类中的 sort 方法里做了一点修改
if (tableData instanceof MapTableData){
Collections.reverse(dataList);

        }

因为使用 json 一般情况下都是接口返回的数据,可以让后台给你返回的时候就是排列好的 ,希望对大家有帮助

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant