Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ContentProvider Error #37

Open
abdellah711 opened this issue Feb 2, 2019 · 0 comments
Open

ContentProvider Error #37

abdellah711 opened this issue Feb 2, 2019 · 0 comments

Comments

@abdellah711
Copy link

abdellah711 commented Feb 2, 2019

Hello
I am trying to create a content provider to get info from the database and display it in a listview but when I used the provider nothing diplayed in the list and I got this error in the logcat :
2019-02-02 14:06:38.195 1294-1331/com.example.android.pet E/ActivityThread: Failed to find provider info for com.example.android.pets

Here is the manifest:
`

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".EditorActivity">
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value=".MainActivity" />
    </activity>

    <provider
        android:name=".data.PetProvider"
        android:authorities="com.example.android.pet"
        android:enabled="true"
        android:exported="false"></provider>
</application>

`

and here is the query method in the provider:

private PetDbHelper petDbHelper; public static final String LOG_TAG = PetProvider.class.getSimpleName(); private static final int PETS = 100; private static final int PET_ID = 101; private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); static { sUriMatcher.addURI(PetContract.CONTENT_AUTHORITY, PetContract.PATH_PETS, PETS); sUriMatcher.addURI(PetContract.CONTENT_AUTHORITY, PetContract.PATH_PETS + "/#", PET_ID); } @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { SQLiteDatabase database = petDbHelper.getReadableDatabase(); Cursor cursor; int match = sUriMatcher.match(uri); switch (match) { case PETS: cursor = database.query(PetContract.PetEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; case PET_ID: selection = PetContract.PetEntry._ID + "=?"; selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) }; cursor = database.query(PetContract.PetEntry.TABLE_NAME, projection, selection, selectionArgs, null, null, sortOrder); break; default: throw new IllegalArgumentException("Cannot query unknown URI " + uri); } return cursor; }

Please help me , and thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant