2011-11-21 55 views
0

我已完成開發應用程序的第一階段。我想測試它在一個實際設備所以掛接我的手機到我的電腦和安裝的應用程序。此應用程序使用一個數據庫,所以當我在我的手機上運行我的應用程序是在運行時拋出一個錯誤如何在活動的運行時插入數據庫?

W/System.err(21912): android.database.sqlite.SQLiteException: no such table: UserTable: , while compiling: SELECT * FROM UserTable WHERE username='null' 

我如何可以插入我的數據庫到我的設備?

通過Eclipse插入它的常規方法無法工作,因爲根訪問被移動電話阻止。

+0

這裏粘貼一些代碼.. –

+0

得到了我的答案。 參考鏈接 http://stackoverflow.com/questions/7268908/access-the-phone-internal-storage-to-push-in-sqlite-database-file – Vinoth

回答

0

請參照本指南:

http://www.vogella.de/articles/AndroidSQLite/article.html

創建新表,你必須把代碼寫在onCreate(SQLiteDatabase database)方法,然後在

onUpgrade(SQLiteDatabase database, int oldVersion, 
      int newVersion) pass the new version. 
+0

我沒有創造一個新表,或創建一個新的數據庫。我已經有了一個必須插入到測試設備中的數據庫。 – Vinoth

+0

您的設備是否與PC連接?如果是的話請分離它然後嘗試,因爲您的設備內存被PC使用。 –

1
public class _DBHelper extends SQLiteOpenHelper { 
    @Override 
     public void onCreate(SQLiteDatabase db) { 
      try { 
       db.execSQL(strCREATE_TABLE1); 
       InitTables(db); 
      } catch (Exception e) { 
       Log.i(this.getClass().getName(), e.getMessage()); 
      } 

     } 

     private void InitTables(SQLiteDatabase db) { 
      ContentValues cv = new ContentValues(); 
      cv.put("colName", "..."); 
      //.. 
      db.insert("MyTable", "id", cv); 
     } 

    } 
+0

這看起來很有前途!現在嘗試。 – Vinoth

相關問題