未能找到供应商信息
Failed to find provider info
我在使用 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
感谢您的任何建议。
<provider android:authorities="com.example"
我想你忘了这里的东西。
我也没有看到您的 ContentProvider class.
我在使用 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
感谢您的任何建议。
<provider android:authorities="com.example"
我想你忘了这里的东西。 我也没有看到您的 ContentProvider class.