Creating tables in sqlite database on android

0 votes
@Override
        public void onCreate(SQLiteDatabase db)
        {
            try{
                db.execSQL("create table " +          NotificationManager.getUserStatic(context) + "log ("+
                KEY_TIME +" INTEGER primary key, "+ KEY_TEXT +" TEXT not null);");

            }
            catch (SQLException e) {
                e.printStackTrace();
            }
        }

        /**
         * onOpen method called when app is opening.
         */

        @Override
        public void onOpen(SQLiteDatabase db)
        {
            try{
                System.out.println("tophere");
                db.execSQL("create table if not exists "+DATABASE_NAME+"." + NotificationManager.getUserStatic(context) + "log ("+
                KEY_TIME +" INTEGER primary key, "+ KEY_TEXT +" TEXT not null);");
                System.out.println("downhere");
            }
            catch (SQLException e){
                e.printStackTrace();
            }
        }

We have the code necessary to build a database for an application. The issue is that, as far as we can determine, the tables aren't created, thus whenever we try to insert data into or read from them, the programme fails. The System.out is the last thing we attempted. Printlns are used to identify where an error occurs. We can read the top portion of the log, but it never gets to the bottom part, so we assume something is failing there. The database should be there because we verified using DDMS that it is in the right place, but for some reason, it cannot be found (line 2 and 3 in the log).

Any suggestions?

The error log:

04-27 10:45:46.768: I/System.out(6441): tophere
04-27 10:45:46.772: I/SqliteDatabaseCpp(6441): sqlite returned: error code = 1, msg = unknown database NOPO, db=/data/data/dmri.nopo/databases/NOPO
04-27 10:45:46.772: W/System.err(6441): android.database.sqlite.SQLiteException: unknown database NOPO: , while compiling: create table if not exists NOPO.log (time INTEGER primary key, text TEXT not null);
04-27 10:45:46.792: W/System.err(6441):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-27 10:45:46.792: W/System.err(6441):     at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:68)
04-27 10:45:46.811: W/System.err(6441):     at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:134)
04-27 10:45:46.811: W/System.err(6441):     at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-27 10:45:46.811: W/System.err(6441):     at android.database.sqlite.SQLiteStatement.acquireAndLock(SQLiteStatement.java:260)
04-27 10:45:46.811: W/System.err(6441):     at android.database.sqlite.SQLiteStatement.executeUpdateDelete(SQLiteStatement.java:84)
04-27 10:45:46.811: W/System.err(6441):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1899)
04-27 10:45:46.823: W/System.err(6441):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1839)
04-27 10:45:46.823: W/System.err(6441):     at dmri.nopo.DBAdapter$DatabaseHelper.onOpen(DBAdapter.java:67)
04-27 10:45:46.823: W/System.err(6441):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:180)
04-27 10:45:46.902: W/System.err(6441):     at dmri.nopo.DBAdapter.open(DBAdapter.java:86)
04-27 10:45:46.912: W/System.err(6441):     at dmri.nopo.LogManager.readLogFile(LogManager.java:32)
04-27 10:45:46.912: W/System.err(6441):     at dmri.nopo.LogActivity.onCreate(LogActivity.java:25)
04-27 10:45:46.921: W/System.err(6441):     at android.app.Activity.performCreate(Activity.java:4465)
04-27 10:45:46.921: W/System.err(6441):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-27 10:45:46.931: W/System.err(6441):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-27 10:45:46.931: W/System.err(6441):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-27 10:45:46.941: W/System.err(6441):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-27 10:45:46.941: W/System.err(6441):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-27 10:45:46.953: W/System.err(6441):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 10:45:46.953: W/System.err(6441):     at android.os.Looper.loop(Looper.java:137)
04-27 10:45:46.972: W/System.err(6441):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-27 10:45:46.972: W/System.err(6441):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 10:45:46.972: W/System.err(6441):     at java.lang.reflect.Method.invoke(Method.java:511)
04-27 10:45:46.982: W/System.err(6441):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-27 10:45:46.982: W/System.err(6441):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-27 10:45:46.992: W/System.err(6441):     at dalvik.system.NativeStart.main(Native Method)
04-27 10:45:47.002: I/SqliteDatabaseCpp(6441): sqlite returned: error code = 1, msg = no such table: log, db=/data/data/dmri.nopo/databases/NOPO
04-27 10:45:47.012: D/AndroidRuntime(6441): Shutting down VM
04-27 10:45:47.012: W/dalvikvm(6441): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
04-27 10:45:47.181: E/AndroidRuntime(6441): FATAL EXCEPTION: main
04-27 10:45:47.181: E/AndroidRuntime(6441): java.lang.RuntimeException: Unable to start activity ComponentInfo{dmri.nopo/dmri.nopo.LogActivity}: android.database.sqlite.SQLiteException: no such table: log: , while compiling: SELECT time, text FROM log
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread.access$600(ActivityThread.java:123)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.os.Looper.loop(Looper.java:137)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread.main(ActivityThread.java:4424)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at java.lang.reflect.Method.invokeNative(Native Method)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at java.lang.reflect.Method.invoke(Method.java:511)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at dalvik.system.NativeStart.main(Native Method)
04-27 10:45:47.181: E/AndroidRuntime(6441): Caused by: android.database.sqlite.SQLiteException: no such table: log: , while compiling: SELECT time, text FROM log
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteCompiledSql.(SQLiteCompiledSql.java:68)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:127)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteProgram.(SQLiteProgram.java:94)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteQuery.(SQLiteQuery.java:53)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at dmri.nopo.DBAdapter.getAllSMS(DBAdapter.java:116)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at dmri.nopo.LogManager.readLogFile(LogManager.java:34)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at dmri.nopo.LogActivity.onCreate(LogActivity.java:25)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.Activity.performCreate(Activity.java:4465)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-27 10:45:47.181: E/AndroidRuntime(6441):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
04-27 10:45:47.181: E/AndroidRuntime(6441):     ... 11 more
Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
522 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Database

0 votes
0 answers

Create SQLite database in android

In my project, I want to construct ...READ MORE

Sep 4, 2022 in Database by Kithuzzz
• 38,000 points
514 views
0 votes
0 answers

Update Query with INNER JOIN between tables in 2 different databases on 1 server

Both databases are on the same server. db1 ...READ MORE

Aug 12, 2022 in Database by Kithuzzz
• 38,000 points
628 views
0 votes
0 answers

Creating a new database and new connection in Oracle SQL Developer

I've introduced SQL Developer to my framework. ...READ MORE

Aug 12, 2022 in Database by Kithuzzz
• 38,000 points
725 views
0 votes
0 answers

Get size of all tables in database

A sizable SQL Server database has been ...READ MORE

Aug 22, 2022 in Database by Kithuzzz
• 38,000 points
451 views
0 votes
0 answers

Caused by: android.database.sqlite.SQLiteException: no such table: (code 1) Android

A SQLite database is present in our ...READ MORE

Aug 22, 2022 in Database by Kithuzzz
• 38,000 points
2,878 views
0 votes
0 answers

How do I get list of all tables in a database using TSQL?

How can I find out the names ...READ MORE

Aug 30, 2022 in Database by Kithuzzz
• 38,000 points
477 views
0 votes
0 answers

How to retrieve data from sqlite database in android and display it in TextView

I'm studying Android. I'm having trouble solving ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
4,841 views
0 votes
0 answers

SQLite in Android How to update a specific row

For a time now, I've been attempting ...READ MORE

Aug 11, 2022 in Database by Kithuzzz
• 38,000 points
1,735 views
0 votes
0 answers

Displaying ALL data from sqlite database into listview in tabbed activity

I've been struggling with this problem for ...READ MORE

Aug 20, 2022 in Database by Kithuzzz
• 38,000 points
3,185 views
0 votes
0 answers

How to store image in SQLite database

I want to upload an image from ...READ MORE

Aug 22, 2022 in Database by Kithuzzz
• 38,000 points
3,072 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP