2010-07-15 70 views
-4
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); 
    } 
+1

你的问题是什么? – CommonsWare 2010-07-16 00:46:46

+0

我上面出现错误。即使我在IF之前定义变量。是否有可能使用上面的代码?...(一个if语句跳过记录,如果它不对应) – Brian 2010-07-16 01:49:03

回答

2

“from”和“to”只存在于if()语句的范围内。无论如何不会有多少意义 - 即使他们这样做了,他们的内容将是未定义的(或者在Java的情况下为空),并立即崩溃您的应用程序。

我不知道你在做什么,但是你可能还需要在if()块内部的底部两条语句。

+0

对不起,这是我多年来第一次使用java。 这是工作列表适配器的代码,不包含IF语句。我想阻止记录被列出,除非特定字段匹配变量。 – Brian 2010-07-16 18:08:33