Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8482609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:51:56+00:00 2026-06-10T19:51:56+00:00

For my application, I already have a readymade database (i.e. it’s stored in the

  • 0

For my application, I already have a readymade database (i.e. it’s stored in the assets folder named example.sqlite with value inserted into it.)

This is the my class Database Helper ::

package com.huskerit.util;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.huskerit.model.AllSportData;

public class DatabaseHelper extends SQLiteOpenHelper  {
//private static final int DATABASE_VERSION = 1;

// Table name
public static final String TABLE = "all_team";
public static final String TABLE_SELECTED = "selected_team";
// Columns
public static final String ID = "id";
public static final String NAME = "name";
public static final String CATEGORY1 = "category1";
public static final String CATEGORY2 = "category2";

public static SQLiteDatabase database;
private final Context myContext;

public DatabaseHelper(Context context) 
{
    super(context, Constant.DB_NAME, null, 1);
    this.myContext = context;
}

public void onCreate(SQLiteDatabase db) 
{
}

public void createDataBase() throws IOException
{
    boolean dbExist = checkDataBase();
    System.out.println("~~~~~~~~"+dbExist);
    if(dbExist)
    {
        //do nothing - database already exist
    }
    else
    {
        //By calling this method and empty database will be created into the default system path
        //of your application so we are gonna be able to overwrite that database with our database.
        DatabaseHelper.this.getReadableDatabase();
        try 
        {
            this.close();   
            copyDataBase();
        } 
        catch (Exception e) 
        {
            e.printStackTrace();
            System.out.println(e.getMessage());
        }
    }
}

/**
 * Check if the database already exist to avoid re-copying the file
 * each time you open the application.
 * @return true if it exists, false if it doesn't
 */
private boolean checkDataBase()
{
    SQLiteDatabase checkDB = null;

    try
    {
        String myPath = Constant.DB_PATH + Constant.DB_NAME;
        checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

    }
    catch(SQLiteException e)
    {
        //database does't exist yet.
        e.printStackTrace();
    }

    if(checkDB != null)
    {
        checkDB.close();
    }

    return checkDB != null ? true : false;
}

/**
 * Copies your database from your local assets-folder to the just created empty database in the
 * system folder, from where it can be accessed and handled.
 * This is done by transfering bytestream.
 * */
private void copyDataBase() throws IOException{
    //Open your local db as the input stream

    // Path to the just created empty db
    String outFileName = Constant.DB_PATH + Constant.DB_NAME;

    //Open the empty db as the output stream
    OutputStream myOutput = new FileOutputStream(outFileName);
    InputStream myInput = myContext.getAssets().open(Constant.DB_NAME);
    //transfer bytes from the inputfile to the outputfile
    byte[] buffer = new byte[1024];
    int length;
    while ((length = myInput.read(buffer)) > 0) {
        myOutput.write(buffer, 0, length);
    }
    myInput.close();
    //Close the streams
    myOutput.flush();
    myOutput.close();
}

public void openDataBase() throws SQLException
{
    //Open the database
    String myPath = Constant.DB_PATH + Constant.DB_NAME;
    database = SQLiteDatabase.openDatabase(myPath,null,SQLiteDatabase.OPEN_READWRITE);
}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
{
}
}

Now I am calling the database in my activity like this ::

public class TeamSelectActivity extends Activity
{

public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_teamselect);

    if(Constant.mDatabase == null)
    {
        Constant.mDatabase = new DatabaseHelper(TeamSelectActivity.this);
    }


    try 
    {
        //Constant.mDatabase.createDataBase(); //DataBase();
        Constant.mDatabase.openDataBase();
    } 
    catch (SQLException e) 
    {
        e.printStackTrace();
    }
}
}

This is the my log trace ::

I/Database(13203): sqlite returned: error code = 14, msg = cannot open file at source line 25467
E/Database(13203): sqlite3_open_v2("/data/data/com.huskerit.login/databases/wimbim.sqlite",  &handle, 2, NULL) failed
W/System.err(13203): android.database.sqlite.SQLiteException: unable to open database file
at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1849)
at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
at com.huskerit.util.DatabaseHelper.openDataBase(DatabaseHelper.java:130)
at com.huskerit.login.TeamSelectActivity.onCreate(TeamSelectActivity.java:93)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)

I am unable to figure it out where i am doing wrong ..
Any help would be appreciated ..

Thanks in Advance…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T19:51:57+00:00Added an answer on June 10, 2026 at 7:51 pm

    this is due to the method checkDataBase().
    use the following to check the data

             private boolean checkDataBase() {
            // TODO Auto-generated method stub
             File dbFile = new File(DB_PATH + DB_NAME);
             return dbFile.exists();
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Sqlite Database in my Application, I have already upload my
I have an application in XCode using the sqlite/coredata database and that has already
I already have an application that uses the SQLite database and a listadapter. I
A have an app with that uses an SQL database. The application is already
I already have a User table in my primary application database with an email
I already have an application built in asp.net 3.5 and now I want to
I already have an enterprise Java EE application. I want expose some of the
I already have an iPhone application (version 1.0) available in the App Store and
I have a prism application already in production. I need to create a new
I am currently developing an android application using eclipse and I already have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.