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 7705677
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:55:23+00:00 2026-05-31T23:55:23+00:00

I have created application where i just need to access data form assets folder.

  • 0

I have created application where i just need to access data form assets folder. I am using database helper class to open database but i am unable to access database and i am putting my code

public class DidUMean extends Activity {
DataBaseHelper myDbHelper;
public SQLiteDatabase mydatabase;
String searchWord;
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.didumean);

    myDbHelper = new DataBaseHelper(DidUMean.this);

    didYouMean(searchWord);

}

public void didYouMean(String searchWord) {
    myDbHelper.openDataBase();
    mydatabase = myDbHelper.getWritableDatabase();
    Cursor cc = mydatabase.rawQuery("SELECT COUNT(*) FROM tblVocab",
            null);
    try {
        if (cc.getCount() == 0) {
            System.out.println("----> "+cc.getCount());
        }
    } catch (SQLException sqle) {
        System.out.println(sqle);
        throw sqle;
    } finally {
        myDbHelper.close();
    }
}
}

I am getting following error in Logcat.

03-28 15:12:48.945: ERROR/AndroidRuntime(1995): FATAL EXCEPTION: main
03-28 15:12:48.945: ERROR/AndroidRuntime(1995): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.lauruss.verb2verbe/com.lauruss.verb2verbe.DidUMean}: android.database.sqlite.SQLiteException: unable to open database file
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.os.Looper.loop(Looper.java:123)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread.main(ActivityThread.java:4627)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at java.lang.reflect.Method.invokeNative(Native Method)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at java.lang.reflect.Method.invoke(Method.java:521)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at dalvik.system.NativeStart.main(Native Method)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995): Caused by: android.database.sqlite.SQLiteException: unable to open database file
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1812)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:817)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at com.lauruss.verb2verbe.DataBaseHelper.openDataBase(DataBaseHelper.java:109)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at com.lauruss.verb2verbe.DidUMean.didYouMean(DidUMean.java:27)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at com.lauruss.verb2verbe.DidUMean.onCreate(DidUMean.java:22)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
03-28 15:12:48.945: ERROR/AndroidRuntime(1995):     ... 11 more
  • 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-05-31T23:55:24+00:00Added an answer on May 31, 2026 at 11:55 pm
    public class DataBaseHelper extends SQLiteOpenHelper{
    
    //The Android's default system path of your application database.
    private static String DB_PATH = "/data/data/com.lauruss.verb2verbe/databases/";
    private static String DB_NAME = "v2v.db";
    private SQLiteDatabase myDataBase; 
    private final Context myContext;
    
    /**
     * Constructor
     * Takes and keeps a reference of the passed context in order to access to the application assets and resources.
     * @param context
     */
    public DataBaseHelper(Context context) {
    
        super(context, DB_NAME, null, 1);
        this.myContext = context;
    }   
    

    /**
    * Creates a empty database on the system and rewrites it with your own database.
    * */
    public void createDataBase() throws IOException{

        boolean dbExist = checkDataBase();
    
        if(dbExist){
            Log.d("Rikta", "Database Exist");
            //do nothing - database already exist
    
            }else{
                Log.d("Rikta", "Database Does Not Exist");
                this.getReadableDatabase();
            try {
                copyDataBase();
            } catch (IOException e) {
                throw new Error("Error copying database");
            }
        }
    }
    /**
     * 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 = DB_PATH + DB_NAME;
            Log.d("Maulik", myPath);
        //  checkDB = SQLiteDatabase.openOrCreateDatabase(myPath, null);
            checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
        }catch(SQLiteException e){
            //database does't exist yet.
        }
        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
        InputStream myInput = myContext.getAssets().open(DB_NAME);
    
        // Path to the just created empty db
        String outFileName = DB_PATH + DB_NAME;
        Log.d("copyDataBase", outFileName);
        //Open the empty db as the output stream
        OutputStream myOutput = new FileOutputStream(outFileName);
    
        //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);
        }
        //Close the streams
        myOutput.flush();
        myOutput.close();
        myInput.close();
    }
    public void openDataBase() throws SQLException{
    
        //Open the database
        String myPath = DB_PATH + DB_NAME;
        Log.d("openDatabase", myPath);
        myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.CREATE_IF_NECESSARY);
     }
    
    @Override
    public synchronized void close() {
            if(myDataBase != null)
                myDataBase.close();
            super.close();
    }
    
    @Override
    public void onCreate(SQLiteDatabase db) {
    }
    
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    }
    
        // Add your public helper methods to access and get content from the database.
       // You could return cursors by doing "return myDataBase.query(....)" so it'd be easy
       // to you to create adapters for your views.
    

    }

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an application using Adobe Flex. I took all the files from
I have created one application in flex that is accessing the Java webservice using
I have this web app created using MVC3 and need to make a Windows
I'm using VS 2010 with C# for a Windows Form application. I need to
I need to add some meta data to some rectangles I have created in
Can I create an application with Flex Builder Trial ( that I have just
I have created an application in facebook,all is working fine except the publish to
I have created an application which needs to have a profile box tab which
I have created an application.in the app i start a countdown timer and save
I have created an application that uses settings.settings to store some user specific settings

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.