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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:31:02+00:00 2026-06-03T15:31:02+00:00

I am getting the following LogCat exception when trying to create an SQLite database:

  • 0

I am getting the following LogCat exception when trying to create an SQLite database:

Caused by: android.database.sqlite.SQLiteException: Can’t upgrade read-only database from version 0 to 1

Here is my code:

import static android.provider.BaseColumns._ID;
import static org.inetizen.university_timetable.Constants.DAY_OF_WEEK;
import static org.inetizen.university_timetable.Constants.DURATION;
import static org.inetizen.university_timetable.Constants.MODULE_CODE;
import static org.inetizen.university_timetable.Constants.ROOM;
import static org.inetizen.university_timetable.Constants.START_TIME;
import static org.inetizen.university_timetable.Constants.TABLE_NAME;
import static org.inetizen.university_timetable.Constants.TYPE_OF_SESSION;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TimeTableData extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "timetable.db";
private static final int DATABASE_VERSION = 1;

/** Create a helper object for the TimeTable database **/
public TimeTableData(Context ctx) {
    super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +_ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT " + MODULE_CODE
            + " TEXT NOT NULL " + DAY_OF_WEEK + " TEXT NOT NULL "
            + START_TIME + " INTEGER NOT NULL " + DURATION
            + " INTEGER NOT NULL " + TYPE_OF_SESSION + " TEXT NOT NULL "
            + ROOM + " TEXT NOT NULL )");
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
    onCreate(db);
}
}

Here is my LogCat:

05-09 12:32:04.525: I/Database(601): sqlite returned: error code = 1, msg = near       "module_code": syntax error
05-09 12:32:04.525: E/Database(601): Failure 1 (near "module_code": syntax error) on   0x252588 when preparing 'CREATE TABLE table_name (_id INTEGER PRIMARY KEY AUTOINCREMENT     module_code TEXT NOT NULL day_of_week TEXT NOT NULL start_time INTEGER NOT NULL duration     INTEGER NOT NULL type_of_session TEXT NOT NULL room TEXT NOT NULL );'.
05-09 12:32:04.535: E/SQLiteOpenHelper(601): Couldn't open timetable.db for writing (will try read-only):    
05-09 12:32:04.535: E/SQLiteOpenHelper(601): android.database.sqlite.SQLiteException: near "module_code": syntax error: CREATE TABLE table_name (_id INTEGER PRIMARY KEY AUTOINCREMENT module_code TEXT NOT NULL day_of_week TEXT NOT NULL start_time INTEGER NOT NULL duration INTEGER NOT NULL type_of_session TEXT NOT NULL room TEXT NOT NULL );
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at org.inetizen.university_timetable.TimeTableData.onCreate(TimeTableData.java:26)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at org.inetizen.university_timetable.TimeTable.getClasses(TimeTable.java:57)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at org.inetizen.university_timetable.TimeTable.onCreate(TimeTable.java:46)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.os.Looper.loop(Looper.java:123)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at java.lang.reflect.Method.invoke(Method.java:521)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 12:32:04.535: E/SQLiteOpenHelper(601):    at dalvik.system.NativeStart.main(Native Method)
05-09 12:32:04.545: D/AndroidRuntime(601): Shutting down VM
05-09 12:32:04.545: W/dalvikvm(601): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-09 12:32:04.555: E/AndroidRuntime(601): FATAL EXCEPTION: main
05-09 12:32:04.555: E/AndroidRuntime(601): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.inetizen.university_timetable/org.inetizen.university_timetable.TimeTable}: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 4: /data/data/org.inetizen.university_timetable/databases/timetable.db
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.os.Looper.loop(Looper.java:123)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 12:32:04.555: E/AndroidRuntime(601):  at java.lang.reflect.Method.invokeNative(Native Method)
05-09 12:32:04.555: E/AndroidRuntime(601):  at java.lang.reflect.Method.invoke(Method.java:521)
05-09 12:32:04.555: E/AndroidRuntime(601):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 12:32:04.555: E/AndroidRuntime(601):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 12:32:04.555: E/AndroidRuntime(601):  at dalvik.system.NativeStart.main(Native Method)
05-09 12:32:04.555: E/AndroidRuntime(601): Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 4: /data/data/org.inetizen.university_timetable/databases/timetable.db
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:170)
05-09 12:32:04.555: E/AndroidRuntime(601):  at org.inetizen.university_timetable.TimeTable.getClasses(TimeTable.java:57)
05-09 12:32:04.555: E/AndroidRuntime(601):  at org.inetizen.university_timetable.TimeTable.onCreate(TimeTable.java:46)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 12:32:04.555: E/AndroidRuntime(601):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 12:32:04.555: E/AndroidRuntime(601):  ... 11 more
05-09 12:32:07.325: I/Database(611): sqlite returned: error code = 1, msg = near "module_code": syntax error
05-09 12:32:07.325: E/Database(611): Failure 1 (near "module_code": syntax error) on 0x119778 when preparing 'CREATE TABLE table_name (_id INTEGER PRIMARY KEY AUTOINCREMENT module_code TEXT NOT NULL day_of_week TEXT NOT NULL start_time INTEGER NOT NULL duration INTEGER NOT NULL type_of_session TEXT NOT NULL room TEXT NOT NULL );'.
05-09 12:32:07.335: E/SQLiteOpenHelper(611): Couldn't open timetable.db for writing (will try read-only):
05-09 12:32:07.335: E/SQLiteOpenHelper(611): android.database.sqlite.SQLiteException: near "module_code": syntax error: CREATE TABLE table_name (_id INTEGER PRIMARY KEY AUTOINCREMENT module_code TEXT NOT NULL day_of_week TEXT NOT NULL start_time INTEGER NOT NULL duration INTEGER NOT NULL type_of_session TEXT NOT NULL room TEXT NOT NULL );
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at org.inetizen.university_timetable.TimeTableData.onCreate(TimeTableData.java:26)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:158)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at org.inetizen.university_timetable.TimeTable.getClasses(TimeTable.java:57)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at org.inetizen.university_timetable.TimeTable.onCreate(TimeTable.java:46)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.os.Looper.loop(Looper.java:123)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at java.lang.reflect.Method.invoke(Method.java:521)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 12:32:07.335: E/SQLiteOpenHelper(611):    at dalvik.system.NativeStart.main(Native Method)
05-09 12:32:07.345: D/AndroidRuntime(611): Shutting down VM
05-09 12:32:07.345: W/dalvikvm(611): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
05-09 12:32:07.355: E/AndroidRuntime(611): FATAL EXCEPTION: main
05-09 12:32:07.355: E/AndroidRuntime(611): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.inetizen.university_timetable/org.inetizen.university_timetable.TimeTable}: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 4: /data/data/org.inetizen.university_timetable/databases/timetable.db
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.os.Looper.loop(Looper.java:123)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 12:32:07.355: E/AndroidRuntime(611):  at java.lang.reflect.Method.invokeNative(Native Method)
05-09 12:32:07.355: E/AndroidRuntime(611):  at java.lang.reflect.Method.invoke(Method.java:521)
05-09 12:32:07.355: E/AndroidRuntime(611):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 12:32:07.355: E/AndroidRuntime(611):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 12:32:07.355: E/AndroidRuntime(611):  at dalvik.system.NativeStart.main(Native Method)
05-09 12:32:07.355: E/AndroidRuntime(611): Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 4: /data/data/org.inetizen.university_timetable/databases/timetable.db
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:170)
05-09 12:32:07.355: E/AndroidRuntime(611):  at org.inetizen.university_timetable.TimeTable.getClasses(TimeTable.java:57)
05-09 12:32:07.355: E/AndroidRuntime(611):  at org.inetizen.university_timetable.TimeTable.onCreate(TimeTable.java:46)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 12:32:07.355: E/AndroidRuntime(611):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 12:32:07.355: E/AndroidRuntime(611):  ... 11 more

Any suggestions on how to resolve the exception?

  • 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-03T15:31:04+00:00Added an answer on June 3, 2026 at 3:31 pm

    The SQL syntax you are using doesn’t look to be correct, you’re missing commas. Try with this:

    db.execSQL("CREATE TABLE " + TABLE_NAME + " (" +_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + MODULE_CODE + " TEXT NOT NULL, " + DAY_OF_WEEK + " TEXT NOT NULL, " + START_TIME + " INTEGER NOT NULL, " + DURATION + " INTEGER NOT NULL, " + TYPE_OF_SESSION + " TEXT NOT NULL, " + ROOM + " TEXT NOT NULL)");

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

Sidebar

Related Questions

I am getting following error: Templates can be used only with field access, property
Am getting following error message on calling WCF service: The formatter threw an exception
I am getting following error when I am trying to get WebResponse using WebResponse
I am getting Following Exception while configuring the Connection Pool in Tomcat This is
I'm trying to create an ePub file in android. Below is my source code.
I am getting the IllegalAccessError while running Android instrumentation tests. This is Logcat output:
I am getting following exception from webservices: com.ctc.wstx.exc.WstxUnexpectedCharException: Illegal character ((CTRL-CHAR, code 15)) I
I am getting following error when I am trying to use Convert.FromBase64String The input
Getting the following in LogCat: 03-28 16:18:57.795: WARN/ResourceType(8351): No package identifier when getting name
Im not gettin the following error fixed (logcat): E/AndroidRuntime( 1010): FATAL EXCEPTION: Thread-105 E/AndroidRuntime(

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.