2012-02-19 139 views
0

當我試圖訪問一個表,我有這個錯誤:02-19 16:46:01.677:E/AndroidRuntime(13159):android.database.sqlite.SQLiteException:沒有這樣的表:備註

02-19 16:46:01.677:E/AndroidRuntime(13159):android.database.sqlite.SQLiteException:no such table:notes:INSERT INTO notes(user,text)VALUES('john','testingvalue')

但我創建了表!我在數據庫中有兩個表('用戶'和'筆記'),我以相同的方式訪問它們,但是當我嘗試在表中註釋時,我有這個錯誤。

這是代碼:

package com.loopr; 

import android.content.Context; 
import android.database.sqlite.SQLiteDatabase; 
import android.database.sqlite.SQLiteDatabase.CursorFactory; 
import android.database.sqlite.SQLiteOpenHelper; 

public class SQL extends SQLiteOpenHelper { 

    String createUserTable = "CREATE TABLE users (name TEXT)"; 
    String createNotesTable = "CREATE TABLE notes (user TEXT, text TEXT)"; 

    public SQL(Context context, String name, CursorFactory factory, int version) { 
     super(context, name, factory, version); 
     // TODO Auto-generated constructor stub 
    } 

    @Override 
    public void onCreate(SQLiteDatabase db) { 
     db.execSQL(createNotesTable); 
     db.execSQL(createUserTable); 
    } 

    @Override 
    public void onUpgrade(SQLiteDatabase db, int before, int after) { 
     //Nothing at the moment 
    } 

} 

我能做些什麼?謝謝。

+0

您是否先創建'user'表,然後更新代碼以創建'notes'表? – waqaslam 2012-02-19 16:01:49

+0

嘗試添加';'在你的SQL語句之後。 – Prexx 2012-02-19 16:07:06

回答

0

試着改變int version,並把這個在您的onUpgrade重寫方法:

// Drop the old table. 
db.execSQL("DROP TABLE IF EXISTS notes"); 

// Create a new one. 
onCreate(db); 
0

你能做些什麼?學習在Android上進行調試。閱讀材料this link。找出如何使用DDMS的文件資源管理器從模擬器中提取數據庫。獲取像SQLite Manager(firefox)這樣的工具來查看這些數據庫 - 這對我非常有幫助。此外,您可以使用SQLite Manager在您的數據庫上執行原始的sql語句,從而允許您同時製作sql並進行測試。

相關問題