Questions tagged [sqliteopenhelper]

SQLiteOpenHelper is a class from the Android SDK which can be used for easier handling of a SQLiteDatabase.

Using the SQLiteOpenHelper only requires implementing its two abstract methods(other methods for different events can be implemented if the user chooses) onCreate(used for initializing the database) and onUpgrade(used when the database is being changed). The Android system will call this methods according to the state of the database( not created/created/upgrading) and in return, it will offer the user a valid SQLiteDatabase reference with the methods getWritableDatabase() and/or getReadableDatabase(). More information can be found in the documentation for the SQLiteOpenHelper class.

801 questions
8
votes
2 answers

Getting Context in onCreate in SQLiteOpenHelper

In my android app: How can I get access to Context in the onCreate method of the SQLiteOpenHelper?
yydl
  • 24,284
  • 16
  • 65
  • 104
8
votes
1 answer

SQLiteDatabase.openDatabase vs SQLiteOpenHelper.getReadableDatabase

Is there any difference between these two methods? Both return an opened SQLiteDatabase. Both can create a database if one doesn't exist. SQLiteOpenHelper also has getWriteableDatabase when read/write is needed... Which method should I use and…
GendoIkari
  • 11,734
  • 6
  • 62
  • 104
8
votes
2 answers

How do I delete the file of an Android Room database?

I have implemented a room database which is distributed from a resource file using SQLiteAssetHelper the first time the app is started. The database contains game status data so if the Player wants to start all over again, I want to copy again the…
Kev
  • 557
  • 1
  • 7
  • 26
8
votes
1 answer

How to store the audio/Video file to SQLite database in android.?

Am new to developing, am successfully store the images to database by converting the images in to bytes array and store it to SQLite database in BLOB (find below code). But am not getting how to store audio's/video's into DB any one help me PLZ... …
8
votes
2 answers

attempt to reopen an already-closed object: sqlitequery

So essentially I am querying the DB twice. I don't understand where this error is really coming from because I am not closing the DB anywhere. The code that returns the error runs like this. I've checked around and I just having seen a case like…
TheHamstring
  • 712
  • 2
  • 6
  • 22
8
votes
5 answers

why we need to onUpgrade(); method in SQLiteOpenHelper class

I m following this tutorial.http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/ can any body please make me clear this chunk of code. // Creating Tables @Override public void onCreate(SQLiteDatabase db) { String…
Qadir Hussain
  • 8,721
  • 13
  • 89
  • 124
8
votes
3 answers

Insert JSON data into the SQLite database in android

I want to insert the data from JSON array into the SQLite database. I have created two classes CategoryHelper.java and AndroidJSONParsingActivity.java to get the java response. When I run the code got the exception in…
ADB
  • 567
  • 2
  • 5
  • 20
8
votes
3 answers

How does it work SQLiteOpenHelper Context

I have an app with two activities. One of them list several values while the other add new values to a DB. I have a class wich extends from SQLiteOpenHelper and manages the DB connections, queries, etc. Now, I understand that in the constructor of…
leojg
  • 1,156
  • 3
  • 16
  • 40
7
votes
2 answers

SQLiteOpenHelper multiple in-memory databases

android.database.sqlite.SQLiteOpenHelper provides the ability to use an in-memory database if the name argument to its constructor is null: String: of the database file, or null for an in-memory database If SQLiteOpenHelper is instantiated…
arcyqwerty
  • 10,325
  • 4
  • 47
  • 84
6
votes
1 answer

SQLite database migration appears to only partially apply in Espresso test

We have an SQLite database and a corresponding SQLiteOpenHelper subclass. This helper has an onDowngrade implementation that I would like to write an Espresso test for. The full onDowngrade implementation is available here. This is a simplified…
6
votes
1 answer

SQLiteOpenHelper single connection vs multiple connections

I am very much confused regarding access to SQLiteDatabase. Either it should be one connection or multiple connections to have access from multiple threads. I have read many articles including following…
6
votes
1 answer

Trying to test SQLiteOpenHelper but getWritableDatabase() throws Null

I'm trying to write a junit test against my apps database in Android Studio using my SQLiteOpenHelper object. Every time it hits the insert method I get a NullPointerException. I've gone back and forth between using getContext() and a mockContext…
MDM82
  • 71
  • 3
6
votes
2 answers

java - java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow

I'm creating an app which uses SQLiteDatabase to store items of a ListView. But, I get an error while populating the data in the ListView from the Database, and the app crashes. Here's my Database - import java.util.ArrayList; import…
Swap
  • 480
  • 2
  • 7
  • 21
6
votes
3 answers

CursorIndexOutOfBoundsException: Index 1 requested, with a size of 1. Error - Android

I'm working on Android application and when trying to get SQLite database data as TextView (only one record in the table) facing this error. The log and exception: 03-28 01:37:22.137: E/AndroidRuntime(9585): FATAL EXCEPTION: main 03-28 01:37:22.137:…
user2881604
  • 2,330
  • 3
  • 21
  • 38
6
votes
1 answer

"Explicit termination method 'close' not called" what's means?

03-02 04:23:07.015: E/StrictMode(1096): A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks. 03-02 04:23:07.015: E/StrictMode(1096): java.lang.Throwable: Explicit…
user3377566
  • 69
  • 1
  • 2
1 2
3
53 54