CursorLoader实例化似乎使用以前的CursorLoader的URI,而不是作为参数传入的URI。
CursorLoader cursor = new CursorLoader(this, FLASHCARD_CONTENT_URI,
FLASHCARD_FROM, null, null, null);
发出以下错误:
no such column: front (code 1): , while compiling:
SELECT _ID, front, back, FROM deck
传递的URI:
public static final Uri FLASHCARD_CONTENT_URI =
Uri.parse("content://" + AUTHORITY + "/" + FLASHCARD_TABLE_NAME);
我知道这是由DecksProvider而不是FlashcardsProvider处理的事实。
FlashcardsProvider中的UriMatcher:
@Override
public boolean onCreate(){
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(AUTHORITY, "flashcard", FLASHCARDS);
auducards = new AuducardOpenHelper(getContext());
return true;
}
我认为重要的是要提到首先调用DecksIndex类,因此成功完成对DeckProvider的调用。直到我在调用DeckShow onCreate方法时点击其中一个甲板(启动DeckShow活动):
@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);
}
并发生错误。
LoaderManager初始化行:
DeckIndex.java
getLoaderManager().initLoader(0, null, this);
DeckShow.java
getLoaderManager().initLoader(1, null, this);
感谢您查看我的问题并告知我们是否有任何其他详细信息或代码可以提供帮助!
答案 0 :(得分:6)
我遇到了这个问题,并了解到为了添加第二个内容提供商,我不得不:
每个提供商的权限必须是唯一的,并且每个提供商的URL必须与权限相匹配。 URL也必须全部小写。
这是一个假设的配置:
<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);
}
}