Question

My code is correct is assume but even though it gives error coloumn not found for _pay_mode :

LOGCAT :

08-20 05:22:05.398: D/Reading:(17403): Reading all contacts..
08-20 05:22:05.539: D/income(17403): table created with price type date description pay_mode
08-20 05:22:35.164: E/Database(17403): Error inserting income
08-20 05:22:35.164: E/Database(17403): android.database.sqlite.SQLiteException: table income has no column named pay_mode: , while compiling: INSERT INTO income(pay_mode, price, date, type, description) VALUES(?, ?, ?, ?, ?);
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1151)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1571)
08-20 05:22:35.164: E/Database(17403):  at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1428)
08-20 05:22:35.164: E/Database(17403):  at com.parth.targetthebudget.DatabaseHandler.addContact(DatabaseHandler.java:81)
08-20 05:22:35.164: E/Database(17403):  at com.parth.targetthebudget.Add_Income.onClick(Add_Income.java:58)
08-20 05:22:35.164: E/Database(17403):  at android.view.View.performClick(View.java:2485)
08-20 05:22:35.164: E/Database(17403):  at android.view.View$PerformClick.run(View.java:9080)
08-20 05:22:35.164: E/Database(17403):  at android.os.Handler.handleCallback(Handler.java:587)
08-20 05:22:35.164: E/Database(17403):  at android.os.Handler.dispatchMessage(Handler.java:92)
08-20 05:22:35.164: E/Database(17403):  at android.os.Looper.loop(Looper.java:130)
08-20 05:22:35.164: E/Database(17403):  at android.app.ActivityThread.main(ActivityThread.java:3687)
08-20 05:22:35.164: E/Database(17403):  at java.lang.reflect.Method.invokeNative(Native Method)
08-20 05:22:35.164: E/Database(17403):  at java.lang.reflect.Method.invoke(Method.java:507)
08-20 05:22:35.164: E/Database(17403):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
08-20 05:22:35.164: E/Database(17403):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
08-20 05:22:35.164: E/Database(17403):  at dalvik.system.NativeStart.main(Native Method)

OnCreate and OnUpgrade methods :

// Creating Tables
    @Override
        public void onCreate(SQLiteDatabase db) {
            String CREATE_INCOME_TABLE = "CREATE TABLE if not exists " + TABLE_INCOME + "("
                    + KEY_PRICE + "REAL,"  
                    + KEY_TYPE + "TEXT,"
                    + KEY_DATE + "TEXT," 
                    + KEY_DESCRIPTION + "TEXT," 
                    + KEY_PAY_MODE + "TEXT"
                    +")";
            db.execSQL(CREATE_INCOME_TABLE);
            Log.d(TABLE_INCOME, "table created with "+ KEY_PRICE +" "+ KEY_TYPE +" "
                    + KEY_DATE +" " + KEY_DESCRIPTION +" " + KEY_PAY_MODE);
        }

        // Upgrading database
        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // Drop older table if existed
            db.execSQL("DROP TABLE IF EXISTS " + TABLE_INCOME);

            // Create tables again
            onCreate(db);
        }

I had tried changing database version or deleting my app and then re-install it after studying these answers :

Android SQLite Column Not Found Error When Executing Raw Query

SQLite android column not found

But still not getting solution.!!!

Was it helpful?

Solution

It seems to me that

KEY_PAY_MODE + "TEXT"

is pay_modeTEXT. Space shortage?

Also, could it be that the CREATE TABLE is not processed at all if it already exists? Did you try explicitly DROP TABLE or DROP DATABASE just in case?

(Note: I know nothing of Android platform, all these are general SQL ideas)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top