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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:51:53+00:00 2026-05-26T08:51:53+00:00

I have created database by using SQLite Database browser . I have to follow

  • 0

I have created database by using SQLite Database browser . I have to follow this example.
enter image description here

Name of the database is : jokesdatabase.sql,which has one table jokes
i places this in assets folder like this: assets folder

Now, My code is:

DatabaseHelper.java

public class DatabaseHelper extends SQLiteOpenHelper {
private Context mycontext;

private String DB_PATH = "/data/data/a.b.c/databases/";
private static String DB_NAME = "jokesdatabase.sql"; //I have aslo tru .db extenstion
private static String DB_TABLE = "jokes";

public SQLiteDatabase myDataBase;

public DatabaseHelper(Context context) throws IOException {
    super(context, DB_NAME, null, 1);
    this.mycontext = context;
    boolean dbexist = checkdatabase();
    if (dbexist) {
        // System.out.println("Database exists");
        opendatabase();
    } else {
        // System.out.println("Database doesn't exist");
        createdatabase();
    }
}

public void createdatabase() throws IOException {
    boolean dbexist = checkdatabase();
    if (dbexist) {
        System.out.println(" Database exists.");
    } else {
        this.getReadableDatabase();
        try {
            copydatabase();
        } catch (IOException e) {
            throw new Error("Error copying database");
        }
    }
}

private boolean checkdatabase() {
    // SQLiteDatabase checkdb = null;
    boolean checkdb = false;
    try {
        String myPath = DB_PATH + DB_NAME;
        File dbfile = new File(myPath);
        checkdb = SQLiteDatabase.openDatabase(myPath, null,
                SQLiteDatabase.OPEN_READWRITE) != null;
        checkdb = dbfile.exists();
    } catch (SQLiteException e) {
        System.out.println("Database doesn't exist");
    }

    return checkdb;
}

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;

    // Open the empty db as the output stream
    OutputStream myoutput = new FileOutputStream(outfilename);

    // transfer byte to inputfile to 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;
    myDataBase = SQLiteDatabase.openDatabase(mypath, null,
            SQLiteDatabase.OPEN_READONLY);

}

public synchronized void close() {
    if (myDataBase != null) {
        myDataBase.close();
    }
    super.close();
}

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

}

// This will return a cursor containing database records
public Cursor data() {

    Cursor c;
    c = myDataBase.query(DB_TABLE, null, null, null, null, null, null);
    return c;
}

@Override
public void onCreate(SQLiteDatabase arg0) {
    // TODO Auto-generated method stub

}

}

Result.java

Now
Androidmanifest.xml

<application android:icon="@drawable/icon" android:label="@string/app_name">
    <activity android:name=".DatabaseHelper"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".Result" android:label="@string/app_name"></activity>
 </application>

And finally I get following error message on logcat.
enter image description here

Give me, what is the error in my code. I have only want to create database using sqlite browser. please dont give the via coding solution.Correct this problem only. which is link.

  • 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-26T08:51:53+00:00Added an answer on May 26, 2026 at 8:51 am

    Don’t define your DatabaseHelper as activity in your Android manifest, it is not an Activity.

    Create and use your DatabaseHelper from within a Activity, just like any other class.

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

Sidebar

Related Questions

I am new to using the SQLite database in iphone apps. I have created
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
I have a database that I have created using SQL Server Developer 2008. I
I have created a database using the SQLite administrator. It contains 3 tables and
I have created a database using SQLite. I want to update the value of
Im using c# .net windows form application. I have many databases created using sql
I need to create a Firebird Database programmatically using DBExpress. I have done this
I've got two PostgreSQL databases that have been created using the same sql file.
I have created a table on an Oracle 10g database with this structure :
i am creating an app that needs a database. i created it using sqlite

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.