2010-07-15 75 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