开发者

CursorIndexOutOfBoundsException caused by Uri

Here is my LogCat log:

开发者_StackOverflow
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.


You didn't do formulaCursor.moveToFirst()?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜