“No Such Table” Error found in SQLite Android

前端 未结 10 2077
轮回少年
轮回少年 2020-12-06 11:12

I am trying to learn about SQLite databases, but I really hate dealing with any back-end stuff, with a passion. I\'m already hitting walls with a seemingly simple problem. <

相关标签:
10条回答
  • 2020-12-06 11:35

    If for some reason, you dropped the table, you might want to delete the database to force the application to recreate it correctly. Use adb shell and find the database in /data/data/[package_name]/databases/. You can just delete the file.

    0 讨论(0)
  • 2020-12-06 11:35

    Make sure that onCreate method called. I am also facing similar type of problem when creating multiple table. If you create a separate class make sure you first clear all the storage data of your app and then again run it ..It will work fine for me.

    0 讨论(0)
  • 2020-12-06 11:40

    try this one for example for insert:

     public boolean insertBook(String title, String author, String isdn) {
    
            try {
                SQLiteDatabase db = getWritableDatabase();
    
                ContentValues cv = new ContentValues();
                cv.put(TITLE, title);
                cv.put(AUTHOR, author);
                cv.put(ISBN, isdn);
    
                ***try
                 {
                db.insert(TABLE_NAME, null, cv);
    }
     catch ( SQLiteException e)
            {
                onCreate(db);
      db.insert(TABLE_NAME, null, cv);
    }***
    
                db.close();
    
                return true;
            } catch (Exception exp) {
                exp.printStackTrace();
    
                return false;
            }
        }
    
    0 讨论(0)
  • 2020-12-06 11:49

    I had this problem, but cleaning the project did not fixed it.
    It turned out I passed DATABASE_NAME instead of TABLE_NAME.

    0 讨论(0)
  • 2020-12-06 11:51

    Note:

    External Database You Access Time must add for the path in Sqliteopenhelper class

    public final static String DATABASE_PATH = "/data/data/com.example.shortcuts/databases/";

    com.example.shortcuts=Your Package name

    0 讨论(0)
  • 2020-12-06 11:55

    Nothing about this made any sense, as the table existed from the very beginning of the DB, so we tried different things:

    1. uninstalling app

    2. claning cache / data

    3. changing database version number

    4. forcing to copy the database even if it already existed

    0 讨论(0)
提交回复
热议问题