android java.lang.IllegalArgumentException: column 'id' does not exist 错误
来源:互联网 发布:情趣用品淘宝店铺简介 编辑:程序博客网 时间:2024/06/05 00:58
package com.example.showview;import org.w3c.dom.UserDataHandler;import android.annotation.SuppressLint;import android.annotation.TargetApi;import android.content.ContentValues;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import android.os.Build;import android.os.CancellationSignal;@TargetApi(Build.VERSION_CODES.JELLY_BEAN)@SuppressLint("NewApi")public class DBoperation {private Context context;private final String TableName = "sffddsdofdssdfsd";public final String UserName = "UserName";public final String UserAddress = "UserAddress";private SQLiteDatabase sqLiteDatabase;public DBoperation(Context context){this.context = context;}//建立打开数据库public void openOrCreatDatabase(){sqLiteDatabase = context.openOrCreateDatabase(TableName, context.MODE_PRIVATE, null); sqLiteDatabase.execSQL("create TABLE " + TableName + " ( _id INTEGER PRIMARY KEY AUTOINCREMENT,"+UserName+" VARCHAR(50) NOT NULL, " + UserAddress + " VARCHAR(50) NOT NULL )");}//插入用户数据public void insert(User user ){if(sqLiteDatabase != null){ContentValues values = new ContentValues();values.put(UserName, user.UserName);values.put(UserAddress, user.UserAddress);sqLiteDatabase.insert(TableName, "", values);}else {System.out.print("error");}}//查讯全部信息public Cursor selectALL(){if(sqLiteDatabase != null)return sqLiteDatabase.query(false, TableName, new String []{"_id",UserName,UserAddress}, null, null, null, null, null, null, null);else {return null;}}//根据条件查询用户public Cursor selectUser(String selection, String[] selectionArgs, String groupBy, String having, String orderBy, String limit, CancellationSignal cancellationSignal){if(sqLiteDatabase != null)return sqLiteDatabase.query(true, TableName, new String []{UserName,UserAddress}, selection, selectionArgs, groupBy, having, orderBy, limit, cancellationSignal);return null;}//关闭数据库public void closeDatabase(){sqLiteDatabase.close();}}
只展示数据库部分的代码
//查讯全部信息public Cursor selectALL(){if(sqLiteDatabase != null)return sqLiteDatabase.query(false, TableName, new String []{"_id",UserName,UserAddress}, null, null, null, null, null, null, null);else {return null;}}
就是这一小段代码纠结了我2个多小时,一直报java.lang.IllegalArgumentException: column 'id' does not exist
在网上了很长时间终于在一个国外的网站上找到了解释
down vote
I have had similar problem because I was not adding the _id column to the projection argument, so adding _id to the projections argument of the query was the solution. (commented by @nobugs)
7down vote
I have had similar problem because I was not adding the _id column to the projection argument, so adding _id to the projections argument of the query was the solution. (commented by @nobugs)
阅读全文
0 0
- android java.lang.IllegalArgumentException: column 'id' does not exist 错误
- java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException: column 'xxx' does not exist解决方法
- java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException: column '_id' does not exist 的相关
- java.lang.IllegalArgumentException: column '_id' does not exist
- java.lang.IllegalArgumentException: column '_id' does not exist 解决方法
- listview 加载的时候报java.lang.IllegalArgumentException: column ‘_id’ does not exist 错误
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- Android学习----异常(3)---java.lang.IllegalArgumentException: column '_id' does not exist
- Android Caused by: java.lang.IllegalArgumentException: column '_id' does not exist
- 使用 SimpleCursorAdapter 时java.lang.IllegalArgumentException: column '_id' does not exist问题
- java.lang.IllegalArgumentException: Document base does not exist or is not a readable directory错误解决
- android——错误:column ‘_id’ does not exist
- JavaScript 面向对象之二 —— 函数上下文(this的指向)
- 上传图片
- 算法的时间和空间复杂度的分析
- 深度学习AlexNet模型详细分析
- python 中TAB空格补全
- android java.lang.IllegalArgumentException: column 'id' does not exist 错误
- Java类加载过程
- 迭代回溯 ---8皇后
- C语言简易通讯录
- SwipeRefreshLayout(下拉刷新控件)的使用
- Linux基础学习笔记之硬盘空间计量单位换算与计算机数据计量单位换算区别
- 【剑指offer】连续子数组的最大和
- 扩展欧几里得
- 数据库 RBAC权限管理