Uri 引起的 CursorIndexOutOfBoundsException
这是我的 LogCat 日志:
08-25 22:35:27.989: ERROR/AndroidRuntime(327): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
这是获取光标的 onCreate(Bundle)
方法:
private static final String[] PROJECTION = {
Formulas._ID, Formulas.TITLE, Formulas.FORMULA
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
Cursor formulaCursor = managedQuery(uri, PROJECTION, null, null, null);
String formulaName = formulaCursor.getString(formulaCursor.getColumnIndex(Formulas.TITLE));
String formula = formulaCursor.getString(formulaCursor.getColumnIndex(Formulas.FORMULA));
((TextView) findViewById(R.id.formula)).setText(formula);
((TextView) findViewById(R.id.formula_name)).setText(formulaName);
}
这是我实际启动活动的位置:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri formula = ContentUris.withAppendedId(getIntent().getData(), id);
startActivity(new Intent(Intent.ACTION_VIEW, formula));
}
我已经有了自己的内容提供程序,并且正确设置了它。
Here is my LogCat log:
08-25 22:35:27.989: ERROR/AndroidRuntime(327): Caused by: android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 3
Here is the onCreate(Bundle)
method where I get the cursor:
private static final String[] PROJECTION = {
Formulas._ID, Formulas.TITLE, Formulas.FORMULA
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Uri uri = getIntent().getData();
Cursor formulaCursor = managedQuery(uri, PROJECTION, null, null, null);
String formulaName = formulaCursor.getString(formulaCursor.getColumnIndex(Formulas.TITLE));
String formula = formulaCursor.getString(formulaCursor.getColumnIndex(Formulas.FORMULA));
((TextView) findViewById(R.id.formula)).setText(formula);
((TextView) findViewById(R.id.formula_name)).setText(formulaName);
}
And here is where I actually start the activity:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri formula = ContentUris.withAppendedId(getIntent().getData(), id);
startActivity(new Intent(Intent.ACTION_VIEW, formula));
}
I already have my own content provider and I set it up properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有执行
formulaCursor.moveToFirst()
?You didn't do
formulaCursor.moveToFirst()
?