private void datafill()
{
Cursor notesCursor = mDbHelper.fetchAllNotes();
startManagingCursor(notesCursor);
/* JournalRowId is the row id from the first database containing all journal names
All notes are kept in database 2. I want only the notes that correspond to each
journal to be listed, KEY_HOMEID is the non visible field that shows where
each note came from.
*
*/
if (editjournalDbAdapter.KEY_HOMEID == journalRowId){
String[] from = new String[]{editjournalDbAdapter.KEY_HEIGHT};
int[] to = new int[]{R.id.detail1};
}
//Error here "from" and "to" are not defined outside of if statement
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.journaldetailrow, notesCursor, from, to);
setListAdapter(notes);
}
答案 0 :(得分:2)
“from”和“to”仅存在于if()语句的范围内。否则无论如何都没有多大意义 - 即使他们这样做了,他们的内容也将是未定义的(或者,如果是Java,则为null)并立即崩溃你的应用程序。
我不知道你想要完成什么,但你可能也想在if()块中包含底部的两个语句。