No such table sqlite android studio

Google Android — это несложно

Добро пожаловать на форум сайта

SQLiteException: no such table что делать с этим бредом?

SQLiteException: no such table что делать с этим бредом?

Сообщение altwin » 24 дек 2013, 17:54

коротко суть, по скольку блок if отрабатывает -очевидно, что база открыта как минимум на чтение. Путь к базе дефолтный и она создается(что можно посмотреть в файл эксплорере. DbHelper.TABLE_NAME — именно то имя таблицы к которой идет запрос, проверял — в терминале выполнял SQL запрос, к этой базе(выгруженной с устройства) при выполнение которого idea выкинула трассривку ошибки(запрос простой SELECT _id, . и т.д., FROM (DbHelper.TABLE_NAME) ORDER BY _id).

Проблема в том, что в активити пустое, и информация с базы не попадает. а в терминале именно одна ошибка — SQLiteException: no such table: DbHelper.TABLE_NAME, while compiling: SELECT _id, . и т.д., FROM (DbHelper.TABLE_NAME) ORDER BY _id + в логе «дебильная ошибка»(из этого блока).

P.S. наверно нужно добавить, что никакая база в коде вообще не создается, а используется существующая и открывается только на чтение.

Re: SQLiteException: no such table что делать с этим бредом?

Сообщение anber » 24 дек 2013, 18:21

Re: SQLiteException: no such table что делать с этим бредом?

Сообщение altwin » 24 дек 2013, 19:27

который в свою очередь помещает данный из базы в объект класса Curses и далее уже из этих объектов заполняется Map(он мне нужен, поскольку для списка использую кастомный адаптер, кода там не мало, поскольку приходилось сортировать Map объекты, потому переписывать только из за перехода данных в бд не хочу.. мне проще заполнить Map из базы и не трогать существующую логику.)

Читайте также:  Как удалить с андроида все рекламы

Источник

Android SQLite «no such table» exception

I’m starting into SQLite and databases in Android and I just found this issue. I have read a lot of similar questions but I have not found a solution yet.

This is the error I’m getting:

E/AndroidRuntime(529): Caused by: android.database.sqlite.SQLiteException: no such table: ligas_bd: , while compiling: SELECT * FROM ligas_bd

This is my code.

I also checked in my phone with root explorer data/data/mypackagename/databases and the database appears there as normal.

My database and the main table have the same name, as you can see in this pic of SQLite database browser:

I am not creating the table, I created it before using SQLite Database Browser and I am just trying to read from it

I don’t know how, but I finally fixed it. I just started again, this time following this tutorial. Hope it helps!

9 Answers 9

This is only a guess but I can see three possible things are happening here.

  1. Calling this.getReadableDatabase() in your createDatabase() method is automatically creating an empty database.
  2. Your attempt to copy your pre-created database from your assets folder is failing or the database is being copied to the wrong place.
  3. The empty database created in step 1 (above) is the one that is being queried when you call db.rawQuery(. ) from your main code.

To explain further it is usefult to look at the source for SQLiteOpenHelper

When you create an instance of SQLiteOpenHelper it sets things like the database name and version but it does not create the database. Instead, the first call to either getReadableDatabase() or getWritableDatabase() checks to see if the database exists and if it doesn’t it creates it. After creating the empty database, the onCreate(. ) method is called which, in your case, does nothing.

Читайте также:  Command conquer tiberium wars для андроида

On to point 2 (above) — you say that DB_PATH is /data/data/mypackagename/databases . If that is really the case and you have no trailing / then the line.

. will set myPath to /data/data/mypackagename/databasesligas_db . In that case, even if the copy from assets succeeds, the copied database isn’t going to be where you expect it to be.

Finally on point 3 (above) when you call db.rawQuery(. ) the instance that db points to is returned by the previous call to getWritableDatabase() . Assuming the copy from assets has failed or that it has been copied to the incorrect path, db will be pointing at the empty database created in step 1.

The error you get is that the table doesn’t exist and it isn’t an error indicating the database doesn’t exist — the only logical explanation is that it’s performing a query on an empty database and not the one that has been copied from assets .

EDIT: One other thing I meant to mention. It isn’t a good idea to use hard-coded paths to any of the Android directories. For example — although on most devices, the directory where databases are created will be /data/data/

/databases this is not a guarantee. It is much safer if you call the getDatabasePath(. ) method as it will return a File object which can be used to get the path to the databases directory used by the Android database classes.

Источник

Оцените статью