我有一个服务,它在安装应用程序后启动,当服务启动时它会崩溃应用程序。有可能尚未创建数据库文件?我不知道该怎么做。
错误:
07-31 11:41:56.333: E/DatabaseUtils(21572): Writing exception to parcel
07-31 11:41:56.333: E/DatabaseUtils(21572): java.lang.IllegalArgumentException: the bind value at index 2 is null
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:294)
07-31 11:41:56.333: E/DatabaseUtils(21572): at com.piqsho.p.d.h.CP.query(CP.java:542)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.content.ContentProvider.query(ContentProvider.java:652)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:113)
07-31 11:41:56.333: E/DatabaseUtils(21572): at android.os.Binder.execTransact(Binder.java:351)
07-31 11:41:56.333: E/DatabaseUtils(21572): at dalvik.system.NativeStart.run(Native Method)
07-31 11:41:56.417: E/AndroidRuntime(21586): FATAL EXCEPTION: ServiceStartArguments
07-31 11:41:56.417: E/AndroidRuntime(21586): java.lang.IllegalArgumentException: the bind value at index 2 is null
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:137)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.content.ContentProviderProxy.query(ContentProviderNative.java:366)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.content.ContentResolver.query(ContentResolver.java:373)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.content.ContentResolver.query(ContentResolver.java:316)
07-31 11:41:56.417: E/AndroidRuntime(21586): at com.piqsho.p.s.SIMS.getNewChatMessages(SIMS.java:186)
07-31 11:41:56.417: E/AndroidRuntime(21586): at com.piqsho.p.s.SIMS$ServiceHandler$1.run(SIMS.java:81)
07-31 11:41:56.417: E/AndroidRuntime(21586): at com.piqsho.p.s.SIMS$ServiceHandler.handleMessage(SIMS.java:73)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.os.Handler.dispatchMessage(Handler.java:107)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.os.Looper.loop(Looper.java:194)
07-31 11:41:56.417: E/AndroidRuntime(21586): at android.os.HandlerThread.run(HandlerThread.java:60)
07-31 11:41:57.428: E/DatabaseUtils(21572): Writing exception to parcel
07-31 11:41:57.428: E/DatabaseUtils(21572): java.lang.IllegalArgumentException: the bind value at index 1 is null
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1314)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:400)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.database.sqlite.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:294)
07-31 11:41:57.428: E/DatabaseUtils(21572): at com.piqsho.p.d.h.CP.query(CP.java:542)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.content.ContentProvider.query(ContentProvider.java:652)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.content.ContentProvider$Transport.query(ContentProvider.java:189)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:113)
07-31 11:41:57.428: E/DatabaseUtils(21572): at android.os.Binder.execTransact(Binder.java:351)
07-31 11:41:57.428: E/DatabaseUtils(21572): at dalvik.system.NativeStart.run(Native Method)
代码:
package com.piqsho.p.d.h;
import java.util.HashMap;
import android.content.ContentProvider;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.UriMatcher;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
public class CP extends ContentProvider {
static final String PROVIDER_NAME = "com.piqsho.provider";
public static final String U_URL = "content://" + PROVIDER_NAME + "/user";
public static final Uri U_CONTENT_URI = Uri.parse(U_URL);
public static final String C_URL = "content://" + PROVIDER_NAME + "/chat";
public static final Uri C_CONTENT_URI = Uri.parse(C_URL);
public static final String CF_URL = "content://" + PROVIDER_NAME
+ "/chat_file";
public static final Uri CF_CONTENT_URI = Uri.parse(CF_URL);
public static final String F_URL = "content://" + PROVIDER_NAME
+ "/friends";
public static final Uri F_CONTENT_URI = Uri.parse(F_URL);
public static final String PV_URL = "content://" + PROVIDER_NAME
+ "/phone_verification";
public static final Uri PV_CONTENT_URI = Uri.parse(PV_URL);
public static final String UP_URL = "content://" + PROVIDER_NAME
+ "/user_pictures";
public static final Uri UP_CONTENT_URI = Uri.parse(UP_URL);
public static final String DATABASE_NAME = "piqsho_android.db";
public static final int DATABASE_VERSION = 1;
private SQLiteDatabase db;
// USER DETAILS
public static final String TABLE_USER = "user";
public static final String COLUMN_ID_USER = "_id";
public static final String COLUMN_USER_ID = "user_id";
public static final String COLUMN_FNAME = "fname";
public static final String COLUMN_ONAMES = "onames";
public static final String COLUMN_EMAIL = "email";
public static final String COLUMN_PHONE = "phone_no";
public static final String COLUMN_LAST_LOGIN = "last_login";
public static final String COLUMN_REGISTER_DATE = "reg_date";
// Database creation sql statement for user
private static final String DATABASE_CREATE_USER = "create table "
+ TABLE_USER + "(" + COLUMN_ID_USER
+ " integer primary key autoincrement, " + COLUMN_USER_ID
+ " integer not null, " + COLUMN_EMAIL + " text null, "
+ COLUMN_PHONE + " text null, " + COLUMN_FNAME + " text null, "
+ COLUMN_ONAMES + " text null," + COLUMN_LAST_LOGIN
+ " text not null, " + COLUMN_REGISTER_DATE + " text not null);";
// C DETAILS
public static final String TABLE_CHAT = "chat";
public static final String COLUMN_ID_CHAT = "_id";
public static final String COLUMN_CHAT_ID = "message_id";
public static final String COLUMN_CHAT_TO = "toId";
public static final String COLUMN_CHAT_FROM = "fromId";
public static final String COLUMN_CHAT_MSG = "message";
public static final String COLUMN_CHAT_SENTTIME = "senttime";
public static final String COLUMN_CHAT_RECD = "recd";
public static final String COLUMN_CHAT_IS_DELETED = "isDeleted";
// Database creation sql statement for chat
private static final String DATABASE_CREATE_CHAT = "create table "
+ TABLE_CHAT + "(" + COLUMN_ID_CHAT
+ " integer primary key autoincrement, " + COLUMN_CHAT_ID
+ " integer null, " + COLUMN_CHAT_TO + " integer not null, "
+ COLUMN_CHAT_FROM + " integer not null, " + COLUMN_CHAT_MSG
+ " text not null, " + COLUMN_CHAT_SENTTIME + " text not null,"
+ COLUMN_CHAT_RECD + " integer not null," + COLUMN_CHAT_IS_DELETED
+ " tinyint not null default '0');";
// CF DETAILS
public static final String TABLE_CHAT_FILE = "chat_file";
public static final String COLUMN_ID_CHAT_FILE = "_id";
public static final String COLUMN_CHAT_FILE_ID = "chat_file_id";
public static final String COLUMN_CHAT_FILE_NAME = "file_name";
public static final String COLUMN_CHAT_MSG_ID = "chat_id";
public static final String COLUMN_CHAT_DATE_TIME = "date_time";
public static final String COLUMN_CHAT_ID_LOCAL = "id_chat";
public static final String COLUMN_CHAT_FILE_IS_DELETED = "isDeleted";
// Database creation sql statement for chat
private static final String DATABASE_CREATE_CHAT_FILE = "create table "
+ TABLE_CHAT_FILE + "(" + COLUMN_ID_CHAT_FILE
+ " integer primary key autoincrement, " + COLUMN_CHAT_FILE_ID
+ " integer null, " + COLUMN_CHAT_FILE_NAME + " text not null,"
+ COLUMN_CHAT_MSG_ID + " integer not null, "
+ COLUMN_CHAT_DATE_TIME + " text not null," + COLUMN_CHAT_ID_LOCAL
+ " text not null," + COLUMN_CHAT_FILE_IS_DELETED
+ " tinyint not null default '0');";
// FRIENDS DETAILS
public static final String TABLE_FRIENDS = "friends";
public static final String COLUMN_ID_FRIENDS = "_id";
public static final String COLUMN_FRIENDS_ID = "id_friends";
public static final String COLUMN_F_USER_ID = "user_id";
public static final String COLUMN_F_ID = "friend_id";
public static final String COLUMN_F_FNAME = "fname";
public static final String COLUMN_F_ONAMES = "onames";
public static final String COLUMN_F_SEX = "sex";
public static final String COLUMN_F_STATUS = "status";
public static final String COLUMN_F_ISONLINE = "is_online";
public static final String COLUMN_F_LAST_ONLINE = "last_online";
public static final String COLUMN_F_DOB = "dob";
public static final String COLUMN_F_OCCUPATION = "occupation";
public static final String COLUMN_F_PROFILE_PIC_NAME = "profile_pic_name";
public static final String COLUMN_F_PHONE_NO = "phone_no";
// Database creation sql statement for friends
private static final String DATABASE_CREATE_FRIEND = "create table "
+ TABLE_FRIENDS + "(" + COLUMN_ID_FRIENDS
+ " integer primary key autoincrement, " + COLUMN_FRIENDS_ID
+ " integer null, " + COLUMN_F_USER_ID + " integer null, "
+ COLUMN_F_ID + " integer null, " + COLUMN_F_FNAME
+ " text null, " + COLUMN_F_ONAMES + " text null, "
+ COLUMN_F_SEX + " text null," + COLUMN_F_STATUS + " text null, "
+ COLUMN_F_ISONLINE + " text null," + COLUMN_F_LAST_ONLINE
+ " text null," + COLUMN_F_DOB + " text null,"
+ COLUMN_F_OCCUPATION + " text null," + COLUMN_F_PROFILE_PIC_NAME
+ " text null," + COLUMN_F_PHONE_NO + " text null);";
// Network Operator DETAILS
public static final String TABLE_PHONE_VERIFICATION = "phone_verification";
public static final String COLUMN_ID_PV = "_id";
public static final String COLUMN_V_CODE = "v_code";
public static final String COLUMN_V_PNO = "phone_number";
public static final String COLUMN_V_COUNTRY = "country";
public static final String COLUMN_V_COUNTRY_CODE = "country_code";
public static final String COLUMN_V_DATE = "date";
public static final String COLUMN_V_STATUS = "status";
// Database creation sql statement for Network Operator
private static final String DATABASE_CREATE_PHONE_VERIFICATION = "create table "
+ TABLE_PHONE_VERIFICATION
+ "("
+ COLUMN_ID_PV
+ " integer primary key autoincrement, "
+ COLUMN_V_CODE
+ " text null, "
+ COLUMN_V_PNO
+ " text null, "
+ COLUMN_V_COUNTRY
+ " text null, "
+ COLUMN_V_COUNTRY_CODE
+ " text null, "
+ COLUMN_V_DATE
+ " text null, "
+ COLUMN_V_STATUS
+ " tinyint not null default '0');";
public static final String TABLE_USER_PICS = "user_pictures";
public static final String COLUMN_ID_USER_PICS = "_id";
public static final String COLUMN_UP_USER_ID = "user_id";
public static final String COLUMN_UP_URL = "url";
public static final String COLUMN_UP_NAME = "name";
public static final String COLUMN_UP_TYPE = "type";
public static final String COLUMN_UP_ACTIVE = "active";
public static final String COLUMN_UP_IS_DELETED = "is_deleted";
public static final String COLUMN_UP_DATE = "date";
private static final String DATABASE_CREATE_USER_PICS = "create table "
+ TABLE_USER_PICS + "(" + COLUMN_ID_USER_PICS
+ " integer primary key autoincrement, " + COLUMN_UP_USER_ID
+ " text null, " + COLUMN_UP_URL + " text null, " + COLUMN_UP_NAME
+ " text null, " + COLUMN_UP_TYPE + " text null, "
+ COLUMN_UP_ACTIVE + " tinyint not null default '0',"
+ COLUMN_UP_IS_DELETED + " text null, " + COLUMN_UP_DATE
+ " text null);";
static final int u = 1;
static final int u_id = 2;
static final int cds = 3;
static final int cds_id = 4;
static final int fds = 5;
static final int fds_id = 6;
static final int pv = 7;
static final int pv_id = 8;
static final int up = 9;
static final int up_id = 10;
static final int cfds = 11;
static final int cfds_id = 12;
// projection map for a query
private static HashMap<String, String> UMap;
private static HashMap<String, String> CDSMap;
private static HashMap<String, String> FDSMap;
private static HashMap<String, String> PVMap;
private static HashMap<String, String> UPMap;
private static HashMap<String, String> CFDSMap;
static final UriMatcher uriMatcher;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, TABLE_USER, u);
uriMatcher.addURI(PROVIDER_NAME, TABLE_USER + "/#", u_id);
uriMatcher.addURI(PROVIDER_NAME, TABLE_CHAT, cds);
uriMatcher.addURI(PROVIDER_NAME, TABLE_CHAT + "/#", cds_id);
uriMatcher.addURI(PROVIDER_NAME, TABLE_CHAT_FILE, cfds);
uriMatcher.addURI(PROVIDER_NAME, TABLE_CHAT_FILE + "/#", cfds_id);
uriMatcher.addURI(PROVIDER_NAME, TABLE_FRIENDS, fds);
uriMatcher.addURI(PROVIDER_NAME, TABLE_FRIENDS + "/#", fds_id);
uriMatcher.addURI(PROVIDER_NAME, TABLE_PHONE_VERIFICATION, pv);
uriMatcher
.addURI(PROVIDER_NAME, TABLE_PHONE_VERIFICATION + "/#", pv_id);
uriMatcher.addURI(PROVIDER_NAME, TABLE_USER_PICS, up);
uriMatcher.addURI(PROVIDER_NAME, TABLE_USER_PICS + "/#", up_id);
}
private DBH dbHelper;
private static class DBH extends SQLiteOpenHelper {
DBH(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE_USER);
db.execSQL(DATABASE_CREATE_CHAT);
db.execSQL(DATABASE_CREATE_CHAT_FILE);
db.execSQL(DATABASE_CREATE_FRIEND);
db.execSQL(DATABASE_CREATE_PHONE_VERIFICATION);
db.execSQL(DATABASE_CREATE_USER_PICS);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHAT);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CHAT_FILE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_FRIENDS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_PHONE_VERIFICATION);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USER_PICS);
onCreate(db);
}
}
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
String id = uri.getLastPathSegment(); // gets the id
switch (uriMatcher.match(uri)) {
case u:
// delete all the records of the table
count = db.delete(TABLE_USER, selection, selectionArgs);
break;
case u_id:
count = db.delete(TABLE_USER, COLUMN_ID_USER
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
case cds:
// delete all the records of the table
count = db.delete(TABLE_CHAT, selection, selectionArgs);
break;
case cds_id:
count = db.delete(TABLE_CHAT, COLUMN_ID_CHAT
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
case cfds:
// delete all the records of the table
count = db.delete(TABLE_CHAT_FILE, selection, selectionArgs);
break;
case cfds_id:
count = db.delete(TABLE_CHAT_FILE, COLUMN_ID_CHAT_FILE
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
case fds:
// delete all the records of the table
count = db.delete(TABLE_FRIENDS, selection, selectionArgs);
break;
case fds_id:
count = db.delete(TABLE_FRIENDS, COLUMN_ID_FRIENDS
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
case pv:
// delete all the records of the table
count = db.delete(TABLE_PHONE_VERIFICATION, selection,
selectionArgs);
break;
case pv_id:
count = db.delete(TABLE_PHONE_VERIFICATION, COLUMN_ID_PV
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
case up:
// delete all the records of the table
count = db.delete(TABLE_USER_PICS, selection, selectionArgs);
break;
case up_id:
count = db.delete(TABLE_USER_PICS, COLUMN_ID_USER_PICS
+ " = "
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
default:
throw new IllegalArgumentException("Unsupported URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
// Get all user records
case u:
return "vnd.android.cursor.dir/vnd.android.provider.cp.user";
// Get a user
case u_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.user";
case cds:
return "vnd.android.cursor.dir/vnd.android.provider.cp.chat";
// Get a chat
case cds_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.chat";
case cfds:
return "vnd.android.cursor.dir/vnd.android.provider.cp.chat";
// Get a chat file
case cfds_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.chat";
case fds:
return "vnd.android.cursor.dir/vnd.android.provider.cp.friends";
// Get a particular friend
case fds_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.friends";
case pv:
return "vnd.android.cursor.dir/vnd.android.provider.cp.phone_verification";
// Get a particular picture
case pv_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.phone_verification";
case up:
return "vnd.android.cursor.dir/vnd.android.provider.cp.user_pictures";
// Get a particular user profile
case up_id:
return "vnd.android.cursor.item/vnd.android.provider.cp.user_pictures";
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
Uri _uri = null;
switch (uriMatcher.match(uri)) {
case u:
long row1 = db.insert(TABLE_USER, "", values);
if (row1 > 0) {
Uri newUri = ContentUris.withAppendedId(U_CONTENT_URI, row1);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
case cds:
long rowc = db.insert(TABLE_CHAT, "", values);
if (rowc > 0) {
Uri newUri = ContentUris.withAppendedId(C_CONTENT_URI, rowc);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
case cfds:
long rowcf = db.insert(TABLE_CHAT_FILE, "", values);
if (rowcf > 0) {
Uri newUri = ContentUris.withAppendedId(CF_CONTENT_URI, rowcf);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
case fds:
long rowf = db.insert(TABLE_FRIENDS, "", values);
if (rowf > 0) {
Uri newUri = ContentUris.withAppendedId(F_CONTENT_URI, rowf);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
case pv:
long rowpv = db.insert(TABLE_PHONE_VERIFICATION, "", values);
if (rowpv > 0) {
Uri newUri = ContentUris.withAppendedId(PV_CONTENT_URI, rowpv);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
case up:
long rowup = db.insert(TABLE_USER_PICS, "", values);
if (rowup > 0) {
Uri newUri = ContentUris.withAppendedId(UP_CONTENT_URI, rowup);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
break;
default:
throw new SQLException("Fail to add a new record into " + uri);
}
return _uri;
}
@Override
public boolean onCreate() {
Context context = getContext();
dbHelper = new DBH(context);
db = dbHelper.getWritableDatabase();
if (db == null)
return false;
else
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_USER);
SQLiteQueryBuilder cqb = new SQLiteQueryBuilder();
cqb.setTables(TABLE_CHAT);
SQLiteQueryBuilder cfqb = new SQLiteQueryBuilder();
cfqb.setTables(TABLE_CHAT_FILE);
SQLiteQueryBuilder fqb = new SQLiteQueryBuilder();
fqb.setTables(TABLE_FRIENDS);
SQLiteQueryBuilder pvqb = new SQLiteQueryBuilder();
pvqb.setTables(TABLE_PHONE_VERIFICATION);
SQLiteQueryBuilder upqb = new SQLiteQueryBuilder();
upqb.setTables(TABLE_USER_PICS);
switch (uriMatcher.match(uri)) {
case u:
qb.setProjectionMap(UMap);
break;
case u_id:
qb.appendWhere(COLUMN_ID_USER + "=" + uri.getLastPathSegment());
break;
case cds:
cqb.setProjectionMap(CDSMap);
break;
case cds_id:
cqb.appendWhere(COLUMN_ID_CHAT + "=" + uri.getLastPathSegment());
break;
case cfds:
cqb.setProjectionMap(CFDSMap);
break;
case cfds_id:
cqb.appendWhere(COLUMN_ID_CHAT_FILE + "="
+ uri.getLastPathSegment());
break;
case fds:
fqb.setProjectionMap(FDSMap);
break;
case fds_id:
fqb.appendWhere(COLUMN_ID_FRIENDS + "=" + uri.getLastPathSegment());
break;
case pv:
pvqb.setProjectionMap(PVMap);
break;
case pv_id:
pvqb.appendWhere(COLUMN_ID_PV + "=" + uri.getLastPathSegment());
break;
case up:
upqb.setProjectionMap(UPMap);
break;
case up_id:
upqb.appendWhere(COLUMN_ID_USER_PICS + "="
+ uri.getLastPathSegment());
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
SQLiteQueryBuilder finalQb = null;
if (uriMatcher.match(uri) == u || uriMatcher.match(uri) == u_id) {
finalQb = qb;
}
if (uriMatcher.match(uri) == cds || uriMatcher.match(uri) == cds_id) {
finalQb = cqb;
}
if (uriMatcher.match(uri) == cfds || uriMatcher.match(uri) == cfds_id) {
finalQb = cfqb;
}
if (uriMatcher.match(uri) == fds || uriMatcher.match(uri) == fds_id) {
finalQb = fqb;
}
if (uriMatcher.match(uri) == pv || uriMatcher.match(uri) == pv_id) {
finalQb = pvqb;
}
if (uriMatcher.match(uri) == up || uriMatcher.match(uri) == up_id) {
finalQb = upqb;
}
/*
* cursor
*/
Cursor c = finalQb.query(db, projection, selection, selectionArgs, null,
null, sortOrder);
/**
* register to watch a content URI for changes
*/
try {
if(c != null && c.getCount() > 0){
c.setNotificationUri(getContext().getContentResolver(), uri);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
if(c != null){
c.close();
}
}
return c;
}
问题出在哪里?
答案 0 :(得分:0)
在您的表格用户中, 您已指定“COLUMN_USER_ID”
COLUMN_USER_ID+ " integer not null,
在用户表中插入数据时,COLUMN_USER_ID在某种程度上为空。 所以创造问题。 插入数据之前,请确保列值不为空。