我在使用SimpleCursorAdapter的过程中遇到了问题:

java.lang.IllegalArgumentException: column '_id' does not exist

这个问题的原因很好找,点进CursorAdapter中就能看到,它需要一个叫"_id"的键值。而且是必须。

而我的数据库的主键是_ID,所以配合不上。那么解决的办法也很简单,query的时候加上as _id就行了。比如你的键值是_ID那么就用select _ID as id, xx,xxxx, from xxx where ......

我的问题不止这么简单,因为我还用了CursorAdapter,人家的构造函数就那么一个,也没有办法加as条件。最后我走了一个比较野的路子,就是把projection的第一个String改成"_ID AS _id ",然后问题解决了,不过这个路子是没有办法的时候才使用的,不推荐。如果哪位朋友有更好的方法麻烦告诉我一下。

java.lang.IllegalArgumentException: column '_id' does not exist问题的解决方案的更多相关文章

  1. Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist

    出错原因:在查询整个sqlite数据库时,没有查询到 "_id" 这一列. 原来的代码是:mSQLiteDatabase.query(table_name, new String[ ...

  2. JMeter学习-027-JMeter参数文件(脚本分发)路径问题:jmeter.threads.JMeterThread: Test failed! java.lang.IllegalArgumentException: File distributed.csv must exist and be readable解决方法

    前些天,在进行分布式参数化测试的时候,出现了如题所示的错误报错信息.此文,针对此做一个简略的重现及分析说明. JMX脚本线程组参数配置如下所示: 参数文件路径配置如下所示: 执行JMX脚本后,服务器对 ...

  3. Tomcat的错误 之 java.lang.IllegalArgumentException: Document base * does not exist

    Tomcat的异常 之 java.lang.IllegalArgumentException: Document base 有些刚开始使用的Tomcat的朋友会出现的问题,明明已经将某个web应用从t ...

  4. java.lang.IllegalArgumentException:Document base ……does not exist or is not a readable directory错误的解决方案

    关于Tomcat的 Document base ……does not exist or is not a readable directory错误 java.lang.IllegalArgumentE ...

  5. tomcat报错java.lang.IllegalArgumentException: Document base XXXXX does not exist or is not a readable directory

    启动tomcat的时候报如下错误: java.lang.IllegalArgumentException: Document base F:\java\tools\tomcat\me-webapps\ ...

  6. java.lang.IllegalArgumentException: Minimum column number is 0

    easyUI的datagrid导出Excel时报如下错误: [2018-06-20 15:00:21] [ERROR] [org.jeecgframework.poi.excel.export.Exc ...

  7. tomcat启动报错:java.lang.IllegalArgumentException: Document base D:\apache-tomcat-6.0.45\webapps\activiti-explorer does not exist or is not a readable directory

    java.lang.IllegalArgumentException: Document base D:\apache-tomcat-6.0.45\webapps\erp does not exist ...

  8. 严重: Error starting static Resources java.lang.IllegalArgumentException:

    严重: Error starting static Resources java.lang.IllegalArgumentException: Document base E:\myworkspace ...

  9. java.lang.IllegalArgumentException: Requested window android.os.BinderProxy@450b2f48 异常处理

    晕死的错误,改了半天也没想到是这样的原因,基础正要呀... 先看一下警告信息: 07-07 08:32:19.540: WARN/WindowManager(74): Failed looking u ...

随机推荐

  1. devexpress 经验笔记

    1.去除 GridView 头上的 "Drag a column header here to group by that column" -->  点击 Run Desig ...

  2. Swift,下标简化方法的调用

    在类(class)当中采用subscript的方法直接用下标 class a{ func b(number:Int)->Int{ return number } subscript(number ...

  3. Kubernetes环境下调整WebLogic JVM基本参数

    基于Kubernetes启动WebLogic后,发现JVM的最大heap size一直在700多M左右,通过 kubectl logs 察看pod启动状态,发现日志中并没有-Xms和-Xmx参数.日志 ...

  4. 轻松加愉快的 Kubernetes 安装教程

    轻松加愉快的 Kubernetes 安装教程 马哥Linux运维 2 days ago 作者:无聊的学习者 来源:见文末 在国内安装 K8S,一直是大家很头痛的问题,各种麻烦,关键是还不知道需要下载什 ...

  5. iOS: Xcode7安装KSImageNamed插件,自动读取图片名称

    官方文档: ## How do I use it?     Build the KSImageNamed target in the Xcode project and the plug-in wil ...

  6. Jedis(Java+Redis) Pool的使用

    今天试了一下Jedis里连接池JedisPool的的使用.代码如下: package com.myapp.jedis.pooldemo; import redis.clients.jedis.Jedi ...

  7. webpack配置:css文件打包、JS压缩打包和HTML文件发布

    一.CSS文件打包 1.在src下新建css文件,在css文件下新建index.css文件,输入以下代码 body{ color:red; font-size:20px; } 2.css建立好后,需要 ...

  8. Python 自用代码(调整日期格式)

    2017年6月28日 to 2017-06-282017年10月27日 to 2017-10-272017年12月1日 to 2017-12-012017年7月1日 to 2017-07-01 #co ...

  9. 五子棋js

    http://www.jb51.net/article/35993.htm <!DOCTYPE html> <html> <head> <meta http- ...

  10. Mysql 中文中繁杂的字 插入报错的 解决方案

    首先 数据库默认编码选用 utf8 连接字符串也相应改成utf8,不能是gb2312