2

每次我单击一个按钮将数据添加到我的内容提供商时,我都会不断收到 LogCat 错误“无法找到提供商信息”

根据过去关于相同问题的帖子,我检查并确保 Provider 在 Manifest XML 的 Application 部分内,并确保 Authorities 一直在写。但我似乎仍然遇到同样的错误。

清单 XML:

 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ag.access"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

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

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="ag.access.Farming"
        android:label="@string/title_activity_farming"
        android:parentActivityName="ag.access.MainActivity" >
        <intent-filter>
            <action android:name="ag.access.Farming" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.MainActivity" />
    </activity>
    <activity
        android:name="ag.access.Dairy"
        android:label="@string/title_activity_dairy"
        android:parentActivityName="ag.access.MainActivity" >
        <intent-filter>
            <action android:name="ag.access.Dairy" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.MainActivity" />
    </activity>
    <activity
        android:name="ag.access.Daily_log"
        android:label="@string/title_activity_daily_log"
        android:parentActivityName="ag.access.Dairy" >
        <intent-filter>
            <action android:name="ag.access.Daily_log" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Dairy" />
    </activity>
    <activity
        android:name="ag.access.Viewlogs"
        android:label="@string/title_activity_viewlogs"
        android:parentActivityName="ag.access.Daily_log" >
        <intent-filter>
            <action android:name="ag.access.Viewlogs" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Daily_log" />
    </activity>
    <activity
        android:name="ag.access.Add_Edit_Cows"
        android:label="@string/title_activity_add__edit__cows"
        android:parentActivityName="ag.access.Dairy" >
        <intent-filter>
            <action android:name="ag.access.Add_Edit_Cows" />
            <category android:name="android.intent.category.DEFAULT" />

        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Dairy" />
    </activity>
    <activity
        android:name="ag.access.Viewcows"
        android:label="@string/title_activity_viewcows"
        android:parentActivityName="ag.access.Add_Edit_Cows" >
        <intent-filter>
            <action android:name="ag.access.Viewcows" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="ag.access.Add_Edit_Cows" />
    </activity>
    <provider
        android:name="ag.access.cowsdb.provider.Cows_Provider"
        android:authorities="ag.access.cowsdb.provider.Cows_Provider">
        </provider>
</application>
</manifest>

内容提供者 Java:

 package ag.access.cowsdb.provider;



 import ag.access.cowsdb.Cowsdatabase;
 import android.content.ContentProvider;
 import android.content.ContentValues;
 import android.content.UriMatcher;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.net.Uri;
 import android.text.TextUtils;
    public class Cows_Provider extends ContentProvider {

private Cowsdatabase cowsdbh;

private static final String Authority = 
        "ag.access.cowsdb.Cows_Provider";
private static final String Cows = "Cows";
public static final Uri Content_Uri = Uri.parse("content://" + Authority + "/" + Cows);
public static final int COWS = 1;
public static final int COWS_ID = 2;    
private static final UriMatcher cURIMatcher =
        new UriMatcher(UriMatcher.NO_MATCH);
static {
    cURIMatcher.addURI(Authority, Cows, COWS);
    cURIMatcher.addURI(Authority, Cows + "/#", COWS_ID);
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {

    int uriType = cURIMatcher.match(uri);
    SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
    int rowsDeleted = 0;

    switch (uriType) {
    case COWS:
        rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, selection, selectionArgs);
        break;
    case COWS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
            rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id, null);
        } else {
        rowsDeleted = mysqldb.delete(Cowsdatabase.DATABASE_TABLE, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
        }
        break;
        default:
            throw new IllegalArgumentException("Unknow URI: " + uri);
}
    getContext().getContentResolver().notifyChange(uri, null);
    return rowsDeleted;
}

@Override
public Uri insert(Uri uri, ContentValues values) {
    int uriType = cURIMatcher.match(uri);

    SQLiteDatabase mydb = cowsdbh.getWritableDatabase();

    long id = 0;
    switch (uriType) {
    case COWS:
        id = mydb.insert(Cowsdatabase.DATABASE_TABLE, null, values);
        break;
        default:
            throw new IllegalArgumentException("Unknow Uri: " + uri);
    }
    getContext().getContentResolver().notifyChange(uri, null);
    return Uri.parse(Cows + "/" + id);
}
@Override
public boolean onCreate() {
    cowsdbh = new Cowsdatabase(getContext(), null, null, 1);
    return false;
}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {
    SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
    qb.setTables(cowsdbh.DATABASE_TABLE);

    int uriType = cURIMatcher.match(uri);

    switch (uriType) {
    case COWS_ID:
        qb.appendWhere(cowsdbh.Key_Cow + "=" + uri.getLastPathSegment());
        break;
    case COWS:
        break;
        default:
        throw new IllegalArgumentException("Unknown URI");

}
    Cursor cursor = qb.query(cowsdbh.getReadableDatabase(), projection, selection, selectionArgs, null, null, sortOrder);
    cursor.setNotificationUri(getContext().getContentResolver(), uri);
    return cursor;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
        String[] selectionArgs) {
    int uriType = cURIMatcher.match(uri);
    SQLiteDatabase mysqldb = cowsdbh.getWritableDatabase();
    int rowsUpdated = 0;

    switch (uriType) {
    case COWS:
        rowsUpdated = mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, selection, selectionArgs);
        break;
    case COWS_ID:
        String id = uri.getLastPathSegment();
        if (TextUtils.isEmpty(selection)) {
            rowsUpdated =
                    mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id, null);
        } else {
            rowsUpdated =
                    mysqldb.update(Cowsdatabase.DATABASE_TABLE, values, Cowsdatabase.Key_Cow + "=" + id + " and " + selection, selectionArgs);
        }
        break;
        default:
            throw new IllegalArgumentException("Unknown URI:" + uri);
        }
      getContext().getContentResolver().notifyChange(uri, null);
      return rowsUpdated;
  }
  @Override
  public String getType(Uri uri) {
    // TODO Auto-generated method stub
    return null;
 }
   }

请帮我解决这个问题。

4

1 回答 1

3

在课堂上,您将授权值设置为“ag.access.cowsdb.Cows_Provider”,而在 Manifest 文件中设置为不同的“ag.access.cowsdb.provider.Cows_Provider”

请设置相同的权限值

于 2013-10-16T06:16:43.880 回答