我有一个表“公司”,包含3列[name,id,address]。但我想只获取“名称”列值。我这样做
Dao<Company, String> dao = getDBHelper().getCompanyDao();
QueryBuilder<Company, String> queryBuilder = dao.queryBuilder();
queryBuilder.orderBy(Company.USERNAME_FIELD_NAME, true);
**queryBuilder.selectColumns("name");**
PreparedQuery<Company> preparedQuery = queryBuilder.prepare();
CloseableIterator<Company> iterator = dao.iterator(preparedQuery);
AndroidDatabaseResults results = (AndroidDatabaseResults) iterator.getRawResults();
Cursor cursor = results.getRawCursor();
但是当我添加“queryBuilder.selectColumns(”name“)”时,应用程序崩溃了。请帮帮我。因为我正在使用cursoradapter填充数据,所以我想要光标。
崩溃日志在这里:
java.lang.NullPointerException
at com.j256.ormlite.stmt.QueryBuilder.appendFieldColumnName(QueryBuilder.java:593)
at com.j256.ormlite.stmt.QueryBuilder.appendColumns(QueryBuilder.java:585)
at com.j256.ormlite.stmt.QueryBuilder.appendStatementStart(QueryBuilder.java:405)
at com.j256.ormlite.stmt.StatementBuilder.appendStatementString(StatementBuilder.java:122)
at com.j256.ormlite.stmt.StatementBuilder.buildStatementString(StatementBuilder.java:106)
at com.j256.ormlite.stmt.StatementBuilder.prepareStatement(StatementBuilder.java:74)
at com.j256.ormlite.stmt.QueryBuilder.prepare(QueryBuilder.java:98)
答案 0 :(得分:0)
但是当我添加“queryBuilder.selectColumns(”name“)
时,应用程序崩溃了
哇。这是一个非常微妙和长期存在的错误。每当您尝试从没有ID字段的实体中选择列时,都会发生这种情况。我添加了这个错误报告:
这已在主干中修复,将在4.49中。这是办理登机手续。
https://github.com/j256/ormlite-core/commit/ee95883040a3618a1d455b44f6bfd6935a8d4ec7