2011-01-31 40 views
1

我一直在關注使用SQL數據庫的教程,我想我遇到了問題,因爲它已經寫了一段時間了。Android SQL錯誤

例如,它有this.createDatabase必須替換this.openOrCreateDatabase,我發現這與谷歌。還有其他問題,我找不到解決方案:查詢,結果,下一個,setListAdapter都顯示錯誤。

這實際上是這個問題,該教程是爲早期的SDK創建的嗎?有人可以告訴我去哪裏去看看已棄用的方法和他們的替代品,或者指出我應該用什麼替換上面的內容?

道歉我剛剛開始與此,希望你明白我的意思。非常感謝幫助。

編輯: 教程是在這裏:http://www.anddev.org/novice-tutorials-f8/working-with-the-sqlite-database-cursors-t319.html

的問題是在下面的代碼,c.first,results.add,c.next,this.setListAdapter最最後一行有錯誤

if (c.first()) { 
          int i = 0; 
          /* Loop through all Results */ 
          do { 
            i++; 
            /* Retrieve the values of the Entry 
            * the Cursor is pointing to. */ 
            String firstName = c.getString(firstNameColumn); 
            int age = c.getInt(ageColumn); 
            String ageColumName = c.getColumnName(ageColumn); 

            /* Add current Entry to results. */ 
            results.add("" + i + ": " + firstName 
            + " (" + ageColumName + ": " + age + ")"); 
          } while (c.next()); 
        } 
      } 

    } catch (FileNotFoundException e) { 
    } finally { 
      if (myDB != null) 
        myDB.close(); 
    } 
    this.setListAdapter(new ArrayAdapter<String>(this, 
      android.R.layout.simple_list_item_1_small, results)); 

}}

+0

順便提一下,您正在參考哪個教程?請分享網址.. – TheCottonSilk 2011-01-31 13:33:14

回答

0

android文檔應該顯示哪些方法已被棄用,以及替換它們的用法。例如,Context.clearWallpaper()

如果你看一下文件,在每個方法名稱的右上方它指出,該方法是在引入的API級別。例如。 openOrCreateDatabase (String path, SQLiteDatabase.CursorFactory factory)API level 1

如果你需要特定方法的幫助,那麼你需要給我們鏈接到教程或(更優選)發佈一些代碼。

編輯
在您鏈接到它本教程的最頂端說:

:警告:對於SDK版本兼容M3-XXX以上

它現在出來的日期。您應該檢查data storage頁面,然後通過@TheCottonSilk在帖子中查看示例

+0

好的謝謝,教程在這裏:http://www.anddev.org/novice-tutorials-f8/working-with-the-sqlite-database-cursors-t319.html – mao 2011-01-31 21:34:14