Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/212.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 内容提供程序更新时出现多个表错误_Java_Android - Fatal编程技术网

Java 内容提供程序更新时出现多个表错误

Java 内容提供程序更新时出现多个表错误,java,android,Java,Android,我正在使用内容提供商制作笔记型应用程序。当我在内容提供商中只有一个表时,它工作得很好,但是现在我添加了另一个表,我一定是弄糟了什么。我可以在应用程序中读取、写入和删除,但当我尝试单击列表项更新/编辑条目时,应用程序崩溃,告诉我有无效的表 我知道这些表不是无效的,因为当我创建新条目时,它会识别它们。我相信这与我的内容提供商有关,因为在我尝试添加第二个表之前,它工作得很好 这是我的密码: 内容提供商 包装com.cossiosinsurance.rentalsafety.contentprovid

我正在使用内容提供商制作笔记型应用程序。当我在内容提供商中只有一个表时,它工作得很好,但是现在我添加了另一个表,我一定是弄糟了什么。我可以在应用程序中读取、写入和删除,但当我尝试单击列表项更新/编辑条目时,应用程序崩溃,告诉我有无效的表

我知道这些表不是无效的,因为当我创建新条目时,它会识别它们。我相信这与我的内容提供商有关,因为在我尝试添加第二个表之前,它工作得很好

这是我的密码:

内容提供商

包装com.cossiosinsurance.rentalsafety.contentprovider2; 导入java.util.array; 导入java.util.HashSet; 导入com.cossioansurance.rentalsafety.database.TodoDatabaseHelper; 导入com.cossioansurance.rentalsafety.database.NoteTable; 导入com.cossiosinsurance.rentalsafety.database.DeviceTable; 导入android.content.ContentProvider; 导入android.content.ContentResolver; 导入android.content.ContentValues; 导入android.content.UriMatcher; 导入android.database.Cursor; 导入android.database.sqlite.SQLiteDatabase; 导入android.database.sqlite.SQLiteQueryBuilder; 导入android.net.Uri; 导入android.text.TextUtils; 公共类MyNoteContentProvider扩展了ContentProvider{ //数据库 私有TodoDatabaseHelper数据库; //用于UriMacher 专用静态最终int TODOS=10; 私有静态最终int TODO_ID=20; 专用静态最终int设备=30; 专用静态最终int设备_ID=40; 私有静态最终字符串权限=com.cossioinsurance.rentalsafety.contentprovider2; 私有静态最终字符串BASE_PATH=todos; 专用静态最终字符串设备\u路径=设备; 公共静态最终Uri内容\u Uri\u TODOS=Uri.parsecontent://+权限 +/+基本路径; 公共静态最终Uri内容\u Uri\u设备=Uri.parsecontent://+权限 +/+设备路径; 公共静态最终字符串内容\u类型\u TODOS=ContentResolver.CURSOR\u DIR\u BASE\u类型 +/待办事项; 公共静态最终字符串内容\u类型\u设备=ContentResolver.CURSOR\u DIR\u BASE\u类型 +/设备; 公共静态最终字符串内容\项\类型=ContentResolver.CURSOR \项\基\类型 +/待办事项; //??? 公共静态最终字符串内容\项\类型2=ContentResolver.CURSOR\项\基\类型 +/设备; 私有静态最终UriMatcher sURIMatcher=新UriMatcherUriMatcher.NO_MATCH; 静止的{ sURIMatcher.addURIAUTHORITY,基本路径,TODOS; sURIMatcher.addURIAUTHORITY,BASE_PATH+/,TODO_ID; sURIMatcher.addURIAUTHORITY,设备路径,设备; sURIMatcher.addURIAUTHORITY,设备路径+/,设备ID; } @凌驾 公共布尔onCreate{ 数据库=新TodoDatabaseHelpergetContext; 返回false; } @凌驾 公共光标查询uri,字符串[]投影,字符串选择, 字符串[]选择符,字符串排序器{ //使用SQLiteQueryBuilder代替查询方法 SQLiteQueryBuilder queryBuilder=newsqlitequerybuilder; //检查调用方是否请求了不存在的列 检查柱投影; //摆桌子 int-uriType=sURIMatcher.matchuri; 开关型{ 待办案件编号: //将ID添加到原始查询中 queryBuilder.appendWhereNoteTable.COLUMN_ID+= +uri.getLastPathSegment; 打破 机箱设备标识: //将ID添加到原始查询中 queryBuilder.appendWhereDeviceTable.COLUMN_ID+= +uri.getLastPathSegment; 打破 待办事项: queryBuilder.setTablesNoteTable.TABLE_TODO; 打破 机箱设备: queryBuilder.setTablesDeviceTable.TABLE\u设备; 打破 违约: 抛出新的IllegalArgumentExceptionUnknown URI:+URI; } SQLiteDatabase db=database.getWritableDatabase; Cursor Cursor=queryBuilder.querydb,投影,选择, selectionArgs,null,null,sortOrder; //确保潜在听众得到通知 cursor.setNotificationUrigetContext.getContentResolver,uri; 返回光标; } @凌驾 公共字符串getTypeUri{ 返回null; } @凌驾 公共Uri插入Uri,内容值{ int-uriType=sURIMatcher.matchuri; SQLiteDatabase sqlDB=database.getWritableDatabase; int rowsDeleted=0; 长id=0; 开关型{ 待办事项: id=sqlDB.insertNoteTable.TABLE_TODO,null,值; 打破 机箱设备: id=sqlDB.insertDeviceTable.TABLE_设备,null,值; 打破 违约: 抛出新的IllegalArgumentExceptionUnknown URI:+URI; } getContext.getContentResolver.notifyChangeuri,null; 返回Uri.parseBASE_PATH+/+id; } //删除的R ows @凌驾 public int deleteUri uri,字符串选择,字符串[]selectionArgs{ int-uriType=sURIMatcher.matchuri; SQLiteDatabase sqlDB=database.getWritableDatabase; int rowsDeleted=0; 开关型{ 待办事项: rowsDeleted=sqlDB.deleteNoteTable.TABLE_TODO,选择, 选择标记; 打破 待办案件编号: 字符串id=uri.getLastPathSegment; 如果TextUtils.isEmptyselection{ rowsDeleted=sqlDB.deleteNoteTable.TABLE_TODO, NoteTable.COLUMN_ID+=+ID, 无效的 }否则{ rowsDeleted=sqlDB.deleteNoteTable.TABLE_TODO, NoteTable.COLUMN_ID+=+ID +和+选择,, 选择标记; } 打破 机箱设备: rowsDeleted=sqlDB.deleteDeviceTable.TABLE\u设备,选择, 选择标记; 打破 机箱设备标识: 字符串id2=uri.getLastPathSegment; 如果TextUtils.isEmptyselection{ rowsDeleted=sqlDB.deleteDeviceTable.TABLE\u设备, NoteTable.COLUMN_ID+=+id2, 无效的 }否则{ rowsDeleted=sqlDB.deleteNoteTable.TABLE_TODO, NoteTable.COLUMN_ID+=+id2 +和+选择,, 选择标记; } 打破 违约: 抛出新的IllegalArgumentExceptionUnknown URI:+URI; } getContext.getContentResolver.notifyChangeuri,null; 返回删除的行; } //更新行 @凌驾 public int updateUri、ContentValues、字符串选择、, 字符串[]selectionArgs{ int-uriType=sURIMatcher.matchuri; SQLiteDatabase sqlDB=database.getWritableDatabase; int rowsUpdated=0; 开关型{ 待办事项: rowsUpdated=sqlDB.updateNoteTable.TABLE_TODO, 价值观 选择 选择标记; 打破 待办案件编号: 字符串id=uri.getLastPathSegment; 如果TextUtils.isEmptyselection{ rowsUpdated=sqlDB.updateNoteTable.TABLE_TODO, 价值观 NoteTable.COLUMN_ID+=+ID, 无效的 }否则{ rowsUpdated=sqlDB.updateNoteTable.TABLE_TODO, 价值观 NoteTable.COLUMN_ID+=+ID +及 +选择, 选择标记; } 打破 机箱设备: rowsUpdated=sqlDB.updateDeviceTable.TABLE\u设备, 价值观 选择 选择标记; 打破 机箱设备标识: 字符串id2=uri.getLastPathSegment; 如果TextUtils.isEmptyselection{ rowsUpdated=sqlDB.updateDeviceTable.TABLE\u设备, 价值观 DeviceTable.COLUMN_ID+=+id2, 无效的 }否则{ rowsUpdated=sqlDB.updateDeviceTable.TABLE\u设备, 价值观 DeviceTable.COLUMN_ID+=+id2 +及 +选择, 选择标记; } 打破 违约: 抛出新的IllegalArgumentExceptionUnknown URI:+URI; } getContext.getContentResolver.notifyChangeuri,null; 返回原始数据; } 私有void checkColumnsString[]投影{ 字符串[]可用={NoteTable.COLUMN_CATEGORY, NoteTable.COLUMN\u摘要、NoteTable.COLUMN\u说明、NoteTable.COLUMN\u电子邮件、NoteTable.COLUMN\u RENTALDATES、, NoteTable.COLUMN_结束日期,NoteTable.COLUMN_时间,NoteTable.COLUMN_位置,NoteTable.COLUMN_注释, NoteTable.COLUMN\u ID、DeviceTable.COLUMN\u ID、DeviceTable.COLUMN\u类别、DeviceTable.COLUMN\u名称、DeviceTable.COLUMN\u类型}; 如果投影!=null{ HashSet requestedColumns=新的HashSetArrays.asListprojection; HashSet availableColumns=新的HashSetArrays.asListavailable; //检查请求的所有列是否都可用 if!availableColumns.containsAllrequestedColumns{ 在投影中抛出新的IllegalArgumentExceptionUnknown列; } } }
} 我解决了这个问题。我的查询集表似乎设置得不太正确。我必须补充一点 queryBuilder.setTablesNoteTable.TABLE_TODO;到查询中的所有案例。我以前没有在身份证案例中添加这一陈述

@凌驾 公共光标查询uri,字符串[]投影,字符串选择, 字符串[]选择符,字符串排序器{ //使用SQLiteQueryBuilder代替查询方法 SQLiteQueryBuilder queryBuilder=newsqlitequerybuilder; //检查调用方是否请求了不存在的列 检查柱投影; //摆桌子 int-uriType=sURIMatcher.matchuri; 开关型{ 待办事项: queryBuilder.setTablesNoteTable.TABLE_TODO; 打破 待办案件编号: queryBui lder.setTablesNoteTable.TABLE_TODO; //将ID添加到原始查询中 queryBuilder.appendWhereNoteTable.COLUMN_ID+= +uri.getLastPathSegment; 打破 机箱设备: queryBuilder.setTablesDeviceTable.TABLE\u设备; 打破 机箱设备标识: queryBuilder.setTablesDeviceTable.TABLE\u设备; //将ID添加到原始查询中 queryBuilder.appendWhereDeviceTable.COLUMN_ID+= +uri.getLastPathSegment; 打破 违约: 抛出新的IllegalArgumentExceptionUnknown URI:+URI; } SQLiteDatabase db=database.getWritableDatabase; Cursor Cursor=queryBuilder.querydb,投影,选择, selectionArgs,null,null,sortOrder; //确保潜在听众得到通知 cursor.setNotificationUrigetContext.getContentResolver,uri; 返回光标; }