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

  • Home
  • SEARCH
  • 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 6547563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:50:47+00:00 2026-05-25T11:50:47+00:00

I wanted to add a new table in my database, and not change the

  • 0

I wanted to add a new table in my database, and not change the other two that I already had. So when the user will make an upgrade to the app, the two tables that were created would remain and a new table would be added to the database. So I did this:

private static class toDoDBOpenHelper extends SQLiteOpenHelper {
    public toDoDBOpenHelper(Context context, String name,
    CursorFactory factory, int version) {
    super(context, name, factory, version);
    }
    // SQL Statement to create a new database.
    private static final String DATABASE_CREATE = "create table " +
    DATABASE_TABLE_1 + " (" + KEY_ID1 + " integer primary key autoincrement, " +
    CLIENT_NAME + " text not null);";

    private static final String DATABASE_CREATE3 = "create table " +
     DATABASE_TABLE_3 + " (" + KEY_ID3 + " integer primary key autoincrement, " +
      DESCRIPTION + " text " + LIDER + " text " + GOAL + " text " +
       PROJECT_ID + " integer );";
    @Override
    public void onCreate(SQLiteDatabase _db) {
    _db.execSQL(DATABASE_CREATE);
    _db.execSQL("CREATE TABLE "+DATABASE_TABLE_2+" ("+ KEY_ID2 + " integer primary key autoincrement, "+PROJECT_NAME + " text not null, " + KEY_CREATION_DATE + " long, " +START_TIME +" text, "+
            START_DATE+ " text, " + END_TIME + " text, "+ END_DATE + " text, " +
            TOTAL + " text, "+ CLIENT_ID + " integer );");
    _db.execSQL("CREATE TABLE "+DATABASE_TABLE_3+" ("+ KEY_ID3 + " integer primary key autoincrement, "+DESCRIPTION + " text, " + LIDER + " text, " + GOAL +" text, "+
             PROJECT_ID + " integer );");
    }
    @Override
    public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) {


    onCreate(_db);
    }
    }

So I basically added the another table in the onCreate method and I called onCreate in onUpgrade. But now the app crashes on the first run after the upgrading.. The users got this error:

java.lang.RuntimeException: Unable to start activity       
ComponentInfo{com.tracking.app/com.tracking.app.Main}: 
android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 
1 to 2: /data/data/com.tracking.app/databases/trackingApp.db
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database 
from version 1 to 2: /data/data/com.tracking.app/databases/trackingApp.db
at 
android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:170)
at com.tracking.app.ToDoDBAdapter.open(ToDoDBAdapter.java:84)
at com.tracking.app.Main.onCreate(Main.java:74)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more

Does it have sth to do with my open() function? This is the code:

public void open() throws SQLiteException {
try {
db = dbHelper.getWritableDatabase();
} catch (SQLiteException ex) {
db = dbHelper.getReadableDatabase();
}
}

If someone has any idea what am i doing wrong please let me know as soon as possible. Thank u 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-05-25T11:50:48+00:00Added an answer on May 25, 2026 at 11:50 am

    try just for this code

    public void open() throws SQLiteException 
    {
        try
        { 
           db = dbHelper.getWritableDatabase(); 
        }
        catch (SQLiteException ex)
        {
        } 
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to add a new property to one of my model (table). Basically
As I'm new to JSF framework, wanted to know how to add the user
I wanted to add a new column to an Android SQLite Database and then
Background: i'm using InstantRails 2.0 I wanted to add a new column to an
I wanted to add <br> after every 2 loops. The loop will run 8
I wanted to add 2 columnts to an MSSQL table by changing class and
Yesterday I wanted to add a boolean field to an Oracle table. However, there
Lets say i wanted to add another variable to the database can anybody tell
Assume I had these tables in my database that is queried by a web
I wanted to add a StackOverflow-style tag input to a blog model of mine.

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.