android - 自定义内容提供者 : error from the emulator (failed to find provider info)

标签 android android-contentprovider

所以我创建了一个简单的内容提供者,但是我遇到了一个错误:

Failed to find provider info for com.b1.BooksContentProvider

我有 2.2 和 3.2 版本的 2 个 AVD 名称(我为它们都写了随机名称)
3.2 因为我使用了 v4 Fragment 支持
所以,我不知道问题是来自 list ,还是来 self 用来启动模拟器的版本。

这是我的 list 文件:

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

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

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".MyBooksActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="vnd.android.cursor.item/mt_books" />
                <data android:mimeType="vnd.android.cursor.dir/mt_books" />
            </intent-filter>
        </activity>
        <provider
            android:authorities="com.b1.BooksContentProvider"
            android:name="com.b1.BooksContentProvider"></provider>

    </application>

</manifest>

以及我的内容提供者的第一部分:

public class BooksContentProvider extends ContentProvider {

    BooksDataBase mDB;
    private static final String AUTHORITY = "com.b1.MyBooksActivity";
    private static final String BASE_PATH = "books";
    public static final Uri CONTENT_URI = Uri.parse("content:// " + AUTHORITY + "/" + BASE_PATH);
    public static final String CONTENT_ITEM_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
        + "/mt_books";
    public static final String CONTENT_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
        + "/mt_books";

    private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);
    private static final int BOOK_DIR = 101;
    private static final int BOOK_ITEM = 102;

    static
    {
        sURIMatcher.addURI(AUTHORITY, BASE_PATH, BOOK_DIR);
        sURIMatcher.addURI(AUTHORITY, BASE_PATH+"/#", BOOK_ITEM);
    }

谢谢你的帮助


更新


好的,其中一个可能的错误是:
我忘了“导入”不同的类
此外,在 fragment XML 中:LinearLayout 不起作用,我不得不在 XML 中单独放置一个“TextView”

最佳答案

private static final String AUTHORITY = "com.b1.MyBooksActivity";

这与您在 <provider> 中的权限不同元素:

<provider
        android:authorities="com.b1.BooksContentProvider"
        android:name="com.b1.BooksContentProvider"></provider>

他们需要匹配。

关于android - 自定义内容提供者 : error from the emulator (failed to find provider info),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8842722/

相关文章:

java - 如何在调整大小时设置不同的小部件图标

android - 如何与 Gmail 客户端共享内部存储文件

Android 内容提供程序 IllegalArgumentException 未知 URL 内容

android - 内容提供商,文件存储在哪里?

android - 我怎样才能像android market一样从服务器安装apks?

java - Android 开发者引用文档中实现另一个接口(interface)的接口(interface)

android - 如何取消注册传感器监听器?

安卓漏洞?在正确项目的项目动画期间,数据库更新后错误的行开始在 ListView 上动画

java - Cursor.moveToNext 错误

android - Hilt - fragment 中的入口点