Reputation: 1476
CursorLoader instantiation seems to be using URI of previous CursorLoader, rather than the URI passed in as an argument.
CursorLoader cursor = new CursorLoader(this, FLASHCARD_CONTENT_URI,
FLASHCARD_FROM, null, null, null);
is giving the following error:
no such column: front (code 1): , while compiling:
SELECT _ID, front, back, FROM deck
URI being passed:
public static final Uri FLASHCARD_CONTENT_URI =
Uri.parse("content://" + AUTHORITY + "/" + FLASHCARD_TABLE_NAME);
I know for a fact that this is being processed by the DecksProvider and not the FlashcardsProvider.
And the UriMatcher in FlashcardsProvider:
@Override
public boolean onCreate(){
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(AUTHORITY, "flashcard", FLASHCARDS);
auducards = new AuducardOpenHelper(getContext());
return true;
}
I think it is important to mention that the DecksIndex class is called first, and thus a call to the DeckProvider is completed successfully. It is not until I click on one of the decks (which starts the DeckShow activity) when the DeckShow onCreate method is called:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getLoaderManager().initLoader(1, null, this);
setContentView(R.layout.activity_deck_show);
mAdapter = new SimpleCursorAdapter(this, R.layout.flashcard_item, null,
FLASHCARD_FROM, FLASHCARD_TO, 0 );
Intent intent = getIntent();
String message = intent.getStringExtra(DeckIndex.EXTRA_MESSAGE);
}
and the error occurs.
LoaderManager init lines:
DeckIndex.java
getLoaderManager().initLoader(0, null, this);
DeckShow.java
getLoaderManager().initLoader(1, null, this);
Thank you for looking at my question and let me know if any additional details or code will help!
Upvotes: 3
Views: 585
Reputation: 751
I've had this problem and learned that in order to add a second content provider, I had to:
The authority for each provider must be unique and the URL for each provider must match the authority. The URL must be all lowercase as well.
Here is a hypothetical configuration:
<application>
<provider android:name="com.acme.ProviderOne"
android:authorities="com.acme.providerone" />
<provider android:name="com.acme.ProviderTwo"
android:authorities="com.acme.providertwo" />
</application
package com.acme
import android.content.ContentProvider;
public class ProviderOne extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse("content://com.acme.providerone/objects");
private static final int ALLROWS = 1;
private static final int SINGLE_ROW = 2;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.acme.providerone", "objects", ALLROWS);
uriMatcher.addURI("com.acme.providerone", "objects/#", SINGLE_ROW);
}
}
package com.acme
import android.content.ContentProvider;
public class ProviderTwo extends ContentProvider {
public static final Uri CONTENT_URI = Uri.parse("content://com.acme.providertwo/objects");
private static final int ALLROWS = 1;
private static final int SINGLE_ROW = 2;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI("com.acme.providertwo", "objects", ALLROWS);
uriMatcher.addURI("com.acme.providertwo", "objects/#", SINGLE_ROW);
}
}
Upvotes: 6