无法找到提供商信息

时间:2015-02-13 10:44:04

标签: android activeandroid

我遇到ActiveAndroid的ContentProvider问题。我正在使用以下实现LoaderCallbacks的ListFragment:

public class OfferingsListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<Cursor>, SwipeRefreshLayout.OnRefreshListener {

public static final String DATETIME_ARG = "datetime";
private OfferingAdapter mAdapter;
private Context mContext;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);        

    mAdapter = new OfferingAdapter(getActivity(), null);
    setListAdapter(mAdapter);
    getActivity().getSupportLoaderManager().initLoader(0, null, this);
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    Loader<Cursor> loader = new CursorLoader(getActivity(), ContentProvider.createUri(OfferingModel.class, null), null, null, null, null);
    return loader;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    mAdapter.swapCursor(data);
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
    mAdapter.swapCursor(null);
}

}

对于适配器,我使用https://github.com/twotoasters/SectionCursorAdapter中的SectionCursorAdapter。这是代码:

public class OfferingAdapter extends SectionCursorAdapter<String, SectionViewHolder, ItemViewHolder> {

private final SquareTransformation mToasterTrans;
private final SquareTransformation mHumanTrans;

public OfferingAdapter(Context context, Cursor cursor) {
    super(context, cursor, 0, R.layout.offeringslistsection_header, R.layout.offeringslist_item);

    mToasterTrans = new SquareTransformation(true);
    mHumanTrans = new SquareTransformation(false);
}

@Override
protected String getSectionFromCursor(Cursor cursor) {
    final OfferingModel model = new OfferingModel();
    model.loadFromCursor(cursor);
    return this.getSectionTitleForItem(model);
}

@Override
protected SectionViewHolder createSectionViewHolder(View sectionView, String section) {
    return new SectionViewHolder(sectionView);
}

@Override
protected void bindSectionViewHolder(int position, SectionViewHolder sectionViewHolder, ViewGroup parent, String section) {
    sectionViewHolder.textView.setText(section);
}

@Override
protected ItemViewHolder createItemViewHolder(Cursor cursor, View itemView) {
    return new ItemViewHolder(itemView);
}

@Override
protected void bindItemViewHolder(ItemViewHolder itemViewHolder, Cursor cursor, ViewGroup parent) {
    final OfferingModel model = new OfferingModel();
    model.loadFromCursor(cursor);

    itemViewHolder.date.setText(model.date);
    itemViewHolder.offeringType.setText(model.type);
    itemViewHolder.experience.setText(model.experience);
    itemViewHolder.checkBoxFavorite.setChecked(model.favorite);
    itemViewHolder.checkBoxOffered.setChecked(model.offered);

    Context context = itemViewHolder.rootView.getContext();
    itemViewHolder.icon.setImageDrawable(context.getResources().getDrawable(getDrawableId(model.type)));
}

public int getDrawableId(String type) {
    if (type.equals(MainActivity.BURNT)){
        return R.drawable.circleblue;
    } else if (type.equals(MainActivity.MEAL)) {
        return R.drawable.circlecyan;
    } else if (type.equals(MainActivity.PEACE)) {
        return R.drawable.circlegreen;
    } else if (type.equals(MainActivity.SIN)) {
        return R.drawable.circlemagenta;
    } else if (type.equals(MainActivity.TRESPASS)) {
        return R.drawable.circlered;
    }

    return R.drawable.circleblue;
}   

@Override
protected int getMaxIndexerLength() {
    return 1;
}

private String getSectionTitleForItem(OfferingModel model) {
    String title = "some title";


    return title;
}

}

我的清单就是这样:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.widmer.offerings.activities"
android:versionCode="1"
android:versionName="1.0">

<!-- Min/target SDK versions (<uses-sdk>) managed by build.gradle -->

<application android:allowBackup="true"
    android:name="com.activeandroid.app.Application"
    android:label="@string/app_name"
    android:icon="@drawable/ic_launcher"
    android:theme="@style/AppTheme">

    <activity android:name=".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=".DetailActivity" />
    <activity android:name=".OverviewActivity"  />
    <activity android:name="de.widmer.offerings.db.AndroidDatabaseManager"  />

    <meta-data android:name="AA_DB_NAME" android:value="offerings.db" />
    <meta-data android:name="AA_DB_VERSION" android:value="1" />

    <provider android:authorities="com.example" android:exported="false" android:name="com.activeandroid.content.ContentProvider" />

</application>

<uses-permission android:name="android.permission.INTERNET" />

不知何故ContextProvider不起作用。我收到了这个错误:

   18419-18581/de.widmer.offerings.activities E/ActivityThread﹕ Failed to find provider info for de.widmer.offerings.activities

我很感激任何建议。

1 个答案:

答案 0 :(得分:2)

<provider android:authorities="com.example" 

我觉得你在这里忘记了什么。 此外,我没有看到您的ContentProvider类。