我想要获取字符串的主要类是带有粗体的
Uri newUri = ContentUris.withAppendedId(
QuestionsProvider.CONTENT_URI,
this.currentQuestion);
Log.d(TAG, "SHOWQUESTION " + " URI="+newUri.toString());
Cursor cursor = cr.query(newUri,
null, null, null, null);
if (cursor.moveToFirst()) {
**question.setText(cursor.getString(
QuestionsProvider.QUESTION_COLUMN)); //HERE I AM GETTING THE ERROR
currentAnswer = cursor.getString(
QuestionsProvider.ANSWER_COLUMN);**
submit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String text;
String answerGiven =
answer.getText().toString();
answer.setText("");
if (answerGiven.
equalsIgnoreCase(currentAnswer))
{text = "Correct";
}else{
text = "Wrong - "+currentAnswer;
Toast.makeText(getApplicationContext(),
text, Toast.LENGTH_SHORT).show();
}
}});
}
cursor.close();
dialog.show();
并在我的清单中,我成功地添加了提供程序并正在加载它应该! 为什么会出现这种错误?我看错了!
答案 0 :(得分:0)
看起来您没有在查询中指定投影:
Cursor cursor = cr.query(newUri, null, null, null, null);
尝试添加要返回的列的投影:
Cursor cursor = cr.query(newUri, new String[] {KEY_ID, KEY_QUESTION, KEY_ANSWER}, null, null, null);
答案 1 :(得分:0)
我找到了解决方案的人!谢谢你帮助我解开嘘:P 这是我找到的解决方案!!
String columns[] = new String[] { QuestionsProvider.KEY_QUESTION, QuestionsProvider.KEY_ANSWER };
Uri mUri = QuestionsProvider.CONTENT_URI;
Cursor cur = managedQuery(mUri, columns, // Which columns to return
QuestionsProvider.KEY_ID+"="+currentQuestionNumber, // WHERE clause; which rows to return(all rows)
null, // WHERE clause selection arguments (none)
null // Order-by clause (ascending by name)