gpt4 book ai didi

java - Uri 引起的 CursorIndexOutOfBoundsException

转载 作者:行者123 更新时间:2023-12-02 08:30:23 25 4
gpt4 key购买 nike

这是我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com