2013-07-25 59 views
0

我有以下查詢一個很奇怪的問題是返回遊標,但計數爲0,雖然數據是存在以dB我檢查了它,我custome內容提供商返回空指針

Cursor cursor = context.getContentResolver().query(VueConstants.CONTENT_URI, 
    new String[] {"aisleId"}, null, null, null); 
Cursor cursor = context.getContentResolver().query(VueConstants.CONTENT_URI, 
    null, null, null, null);                    

下面是查詢ContentProvider類的方法,我在我的URI內容custome提供商已經覆蓋匹配器

private static final UriMatcher URIMATCHER; 

/** uri matchers for articles table and articles fts3 table query method. */ 
static { 
URIMATCHER = new UriMatcher(UriMatcher.NO_MATCH); 
URIMATCHER.addURI(VueConstants.AUTHORITY, VueConstants.AISLES, 
    AISLES_MATCH); 
URIMATCHER.addURI(VueConstants.AUTHORITY, VueConstants.AISLES 
    + "/#", AISLE_MATCH); 
} 

@Override 
public Cursor query(Uri uri, String[] projection, String selection, 
    String[] selectionArgs, String sortOrder) { 
SQLiteDatabase aislesDB = dbHelper.getWritableDatabase(); 
SQLiteQueryBuilder qb = new SQLiteQueryBuilder(); 
Cursor cursor = null; 
String id; 

switch (URIMATCHER.match(uri)) { 
    case AISLES_MATCH: 
    qb.setTables(VueConstants.AISLES); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    Log.e("provider", "Total Aisles marked to Content Provider cursor.getCount()" + cursor.getCount()); 
    break; 
case AISLE_MATCH: 
    qb.setTables(VueConstants.AISLES); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.AISLE_ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
    break; 
case AISLE_IMAGES_MATCH: 
    qb.setTables(VueConstants.AISLE_IMAGES); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    break; 
case IMAGE_MATCH: 
    qb.setTables(VueConstants.AISLE_IMAGES); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.IMAGE_ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
    break; 
case LOOKING_FOR_TABLE_MATCH: 
    qb.setTables(VueConstants.LOOKING_FOR_TABLE); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    break; 
case LOOKING_FOR_ROW_MATCH: 
    qb.setTables(VueConstants.LOOKING_FOR_TABLE); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
    break; 
case OCCATION_TABLE_MATCH: 
    qb.setTables(VueConstants.OCCASION_TABLE); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    break; 
case OCCATION_ROW_MATCH: 
    qb.setTables(VueConstants.OCCASION_TABLE); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
break; 
case CATEGORY_TABLE_MATCH: 
    qb.setTables(VueConstants.CATEGORY_TABLE); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    break; 
case CATEGORY_ROW_MATCH: 
    qb.setTables(VueConstants.CATEGORY_TABLE); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
    break; 
case COMMENTS_TABLE_MATCH: 
    qb.setTables(VueConstants.COMMENTS_ON_IMAGES_TABLE); 
    cursor = qb.query(aislesDB, projection, selection, selectionArgs, 
     null, null, sortOrder); 
    break; 
case COMMENTS_ROW_MATCH: 
    qb.setTables(VueConstants.COMMENTS_ON_IMAGES_TABLE); 
    id = uri.getLastPathSegment(); 
    cursor = qb.query(aislesDB, projection, 
     VueConstants.ID+ "=" + id 
      + (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' 
       : ""), selectionArgs, null, null, null); 
    break; 

} 
cursor.setNotificationUri(getContext().getContentResolver(), uri); 
return cursor; 

}

回答

2

什麼是VueConstants.CONTENT_URI的價值? 您是否嘗試過Uri:

"content://"+VueConstants.AUTHORITY+"/"+ VueConstants.AISLES+"/1" 

"content://"+VueConstants.AUTHORITY+"/"+ VueConstants.AISLES