这是我的 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);
}
这是我实际开始 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));
}
我已经拥有自己的内容提供商,并且已正确设置它。
最佳答案
您没有执行formulaCursor.moveToFirst()
?
关于java - Uri 引起的 CursorIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3570831/