ORMLite get无法获取类Error的下一个结果

时间:2015-07-11 07:54:00

标签: android ormlite

我在Android中使用ORMlite库我随机得到这个错误,我不知道那是什么以及如何修改:

Caused by: java.lang.IllegalStateException: Could not get next result for class [Ljava.lang.String;
            at com.j256.ormlite.stmt.SelectIterator.next

当我使用此方法获取单列时出现此错误:

    public static List getSingleColumn(String query) {
        List<String> columnes = null;
        try {
            columnes = G.CATEGORY.queryRaw(query, new RawRowMapper<String>() {
                @Override
                public String mapRow(String[] columnNames, String[] resultColumns) throws android.database.SQLException {
                    return resultColumns[0];
                }
            }).getResults();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return columnes;
    }

或此代码:

List unread_messages = G.DBHELPER.getSingleColumn("SELECT SUM(read_status) FROM messageslist");

1 个答案:

答案 0 :(得分:1)

尝试更改方法:

public static String getSingleColumn(String query) {
    String columnes = null;
    try {
        columnes = G.CATEGORY.queryRaw(query, new RawRowMapper<String>() {
            @Override
            public String mapRow(String[] columnNames, String[] resultColumns) throws android.database.SQLException {
                return resultColumns[0];
            }
        }).getFirstResult();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return columnes;
}