Home » Android » android – sqlite database not created

android – sqlite database not created

Posted by: admin June 15, 2020 Leave a comment


I am using standard approach which I learned from popular notepad example for building my first app.
But I got stuck into a strange problem.
The SQLite database file (.db) is not being created in /data/data/package/databases. I have cross checked manifest file and OpenHelper file from HeadFirst android dev. Book ( I am using it as a reference ) but I found myself unable to figure out why the database file is not created..
Are there any special permissions or something we need to switch on to get it working??
strange thing is that its working fine for pre-loaded examples. means ‘.db’ file is created for notepad example but when I try, it fails. 🙁
here are my files.

Package – database.test

1. AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<uses-sdk android:minSdkVersion="10" />

    android:label="@string/app_name" >
        android:label="@string/app_name" >


package database.test;

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

public class TestOpenHelper extends SQLiteOpenHelper {

TestOpenHelper(Context context){
public void onCreate(SQLiteDatabase database){
    database.execSQL("create table test_1 " + " (field1 integer primary key, field2 integer);");
public void onUpgrade (SQLiteDatabase database, int oldVersion, int newVersion){
    database.execSQL("drop table if exists test1");


package database.test;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ListView;

public class Database_testActivity extends Activity {
/** Called when the activity is first created. */
public void onCreate(Bundle savedInstanceState) {

    ListView listview = (ListView)findViewById(R.id.test_list);
    TestAdapter ta = new TestAdapter();

    TestOpenHelper openHelper = new TestOpenHelper(this);

I know its a very basic question, but I have been trying to solve this for last fifteen days and now I am completely frustrated.
Please help ..

How to&Answers:

Change this:

database.execSQL("create table test_1 " + " (field1 integer primary key, field2 integer)");

and this TestOpenHelper openHelper = new TestOpenHelper(this); change to SQLiteDatabase db = new TestOpenHelper(this).getWritableDatabase();

You really didn’t created database, you only create instance of your SQLiteOpenHelper but for create or open database you have to use getWritableDatabase() or getReadableDatabase() method.

Exactly from docs:

Create and/or open a database that will be used for reading and