2017-07-31 11 views
0

ContentResolverのquery()メソッドを使用するアクティビティクラスがあり、そのうちの2つにUri & projection[]が設定され、残りが 'null'に設定されています。 同様ただしのContentProviderクラスでquery()メソッドは次のように定義されるコンテンツリゾルバとコンテンツプロバイダの使用時にアプリケーションがクラッシュする

ContentResolver resolverCatalog = getContentResolver(); Cursor cursor = resolverCatalog.query(PetsEntry.CONTENT_URI,projection,null,null,null);

public class PetProvider extends ContentProvider { 

//object made of the helper class for the provider, to get access of the database 
private SQLdbHelper PetdbHelper; 


private static final int PETS = 1; 
private static final int PET_ID = 2; 

private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); 

static { 
    sUriMatcher.addURI(CONTENT_AUTHORITY, PATH_PETS, PETS); 
    sUriMatcher.addURI(CONTENT_AUTHORITY, PATH_PETS_ID, PET_ID); 
}...//class continues 
:PETS & PETS_ID

@Override 
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { 
    // Making an instance of the SQLiteOpenHelper class named as 'SQLdbHelper' 
    SQLdbHelper PetdbHelper = new SQLdbHelper(getContext()); 

    //getting access to database 
    SQLiteDatabase database_query = PetdbHelper.getReadableDatabase(); 

    // This cursor will hold the result of the query 
    Cursor cursor_query; 

    // Figure out if the URI matcher can match the URI to a specific code 
    int match = sUriMatcher.match(uri); 
    switch (match) { 
     case PETS: 
      cursor_query = database_query.query(TABLE_NAME,projection,null,null,null,null,null); 
      break; 

     case PET_ID: 
      selection = PetContract.PetsEntry._ID + "=?"; 
      selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) }; 

      // This will perform a query on the pets table where the _id equals 3 to return a 
      // Cursor containing that row of the table. 
      cursor_query = database_query.query(TABLE_NAME, projection, selection, selectionArgs, 
        null, null, sortOrder); 
      break; 
     default: 
      throw new IllegalArgumentException("Cannot query unknown URI " + uri); 
    } 

    return cursor_query; 
} 

は、以下のように(これのContentProviderクラス内)に定義されています

AndroidManifestには次のように書いてあります。

<provider 
     android:name=".data.PetProvider" 
     android:authorities="com.example.android.petsretry.data" 
     android:exported="false"> 
</provider> 

複数のものを試しましたが、そこから抜け出せませんでした...助けてください! 事前のおかげで...

+0

クラッシュすると実行中のアプリケーションのスタックトレースをポストする必要があります。 – bennerv

答えて

0

てきたが、問題は、Androidマニフェストファイルとあった、正しいコードを解決策を見つけたです:

<provider android:name=".data.PetProvider" android:authorities="com.example.android.petsretry.data" android:exported="false"/> 

すべての「name」が、「当局」と「エクスポート」プロパティには、持っている必要があります&プロバイダの終了タグ... フープ...

関連する問題