Autore Topic: [android.database.sqlite.SQLiteException: no such column: enabled]  (Letto 1339 volte)

Offline psicomant

  • Utente junior
  • **
  • Post: 95
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    OSX 10.6.5
0
Salve.

Ho un problema con sqlite.

Allora, creo questa tabella:
Codice (Java): [Seleziona]
String CREATE_SENSOR_DATABSE ="CREATE TABLE sensors (_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "sensorid INTEGER NOT NULL, " +
                "sensorname TEXT NOT NULL, " +
                "minsensingfreq INTEGER NOT NULL, " +
                "enabled INTEGER NOT NULL DEFAULT 0);";

poi vorrei inserirci delle righe tramite:

Codice (Java): [Seleziona]
public long insertSensor(int id, String sensorname, int freq, int enable)
    {
       
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_SENSORID, id);
        initialValues.put(KEY_SENSORNAME, sensorname);
        initialValues.put(KEY_MINSENSFREQ, freq);
        initialValues.put(KEY_ENABLED, enable);
       
        Log.v(TAG, "insertSensor()");
       
        return db.insert(SENSORS_TABLE, null, initialValues);
    }

e poi recuperare tali valori con:

Codice (Java): [Seleziona]
public Cursor getAllSensors()
    {
        Log.v(TAG, "getAllSensors()");
       
        return db.query(SENSORS_TABLE, new String[] {
                        KEY_ROWID,
                        KEY_SENSORID,
                        KEY_SENSORNAME,
                KEY_MINSENSFREQ,
                KEY_ENABLED},
                null,
                null,
                null,
                null,
                null);
    }

ma mi ritorna questo errore nel logcat:

Codice: [Seleziona]
11-24 19:15:29.632: ERROR/Database(4667): Error inserting enabled=0 minsensingfreq=1 sensorname=Goldfish 3-axis Accelerometer sensorid=1
11-24 19:15:29.632: ERROR/Database(4667): android.database.sqlite.SQLiteException: table sensors has no column named enabled: , while compiling: INSERT INTO sensors(enabled, minsensingfreq, sensorname, sensorid) VALUES(?, ?, ?, ?);
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
11-24 19:15:29.632: ERROR/Database(4667):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
11-24 19:15:29.632: ERROR/Database(4667):     at com.CSAMS.DBAdapterSensors.insertSensor(DBAdapterSensors.java:103)
11-24 19:15:29.632: ERROR/Database(4667):     at com.CSAMS.generalSettings.fillSensorsSpinner(generalSettings.java:115)
11-24 19:15:29.632: ERROR/Database(4667):     at com.CSAMS.generalSettings.onCreate(generalSettings.java:48)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-24 19:15:29.632: ERROR/Database(4667):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-24 19:15:29.632: ERROR/Database(4667):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-24 19:15:29.632: ERROR/Database(4667):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-24 19:15:29.632: ERROR/Database(4667):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-24 19:15:29.632: ERROR/Database(4667):     at android.view.View.performClick(View.java:2408)
11-24 19:15:29.632: ERROR/Database(4667):     at android.view.View$PerformClick.run(View.java:8816)
11-24 19:15:29.632: ERROR/Database(4667):     at android.os.Handler.handleCallback(Handler.java:587)
11-24 19:15:29.632: ERROR/Database(4667):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 19:15:29.632: ERROR/Database(4667):     at android.os.Looper.loop(Looper.java:123)
11-24 19:15:29.632: ERROR/Database(4667):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 19:15:29.632: ERROR/Database(4667):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 19:15:29.632: ERROR/Database(4667):     at java.lang.reflect.Method.invoke(Method.java:521)
11-24 19:15:29.632: ERROR/Database(4667):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-24 19:15:29.632: ERROR/Database(4667):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-24 19:15:29.632: ERROR/Database(4667):     at dalvik.system.NativeStart.main(Native Method)
11-24 19:15:29.632: VERBOSE/DB(4667): error during insertion!!
11-24 19:15:29.652: VERBOSE/DBAdapter(4667): close()
11-24 19:15:29.692: VERBOSE/DBAdapter(4667): open()
11-24 19:15:29.692: VERBOSE/DBAdapter(4667): getAllSensors()
11-24 19:15:29.702: INFO/Database(4667): sqlite returned: error code = 1, msg = no such column: enabled
11-24 19:15:29.712: DEBUG/AndroidRuntime(4667): Shutting down VM
11-24 19:15:29.712: WARN/dalvikvm(4667): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667): FATAL EXCEPTION: main
11-24 19:15:29.752: ERROR/AndroidRuntime(4667): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.CSAMS/com.CSAMS.generalSettings}: android.database.sqlite.SQLiteException: no such column: enabled: , while compiling: SELECT _id, sensorid, sensorname, minsensingfreq, enabled FROM sensors
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.view.View.performClick(View.java:2408)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.view.View$PerformClick.run(View.java:8816)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.os.Handler.handleCallback(Handler.java:587)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.os.Looper.loop(Looper.java:123)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at java.lang.reflect.Method.invoke(Method.java:521)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at dalvik.system.NativeStart.main(Native Method)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667): Caused by: android.database.sqlite.SQLiteException: no such column: enabled: , while compiling: SELECT _id, sensorid, sensorname, minsensingfreq, enabled FROM sensors
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at com.CSAMS.DBAdapterSensors.getAllSensors(DBAdapterSensors.java:119)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at com.CSAMS.generalSettings.onCreate(generalSettings.java:51)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-24 19:15:29.752: ERROR/AndroidRuntime(4667):     ... 18 more


E' come se il campo enabled non lo creasse proprio...perche'?

Grazie!

Offline bradipao

  • Moderatore globale
  • Utente storico
  • *****
  • Post: 4043
  • keep it simple
  • Respect: +567
    • Github
    • Google+
    • bradipao
    • Mostra profilo
  • Dispositivo Android:
    Nexus 5
  • Play Store ID:
    Bradipao
  • Sistema operativo:
    W7
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #1 il: 24 Novembre 2010, 20:38:11 CET »
0
Tramite ADB estrai il file del database dal telefono/emulatore, copiatelo sul pc, aprilo con un visualizzatore di sqlite (c'è anche un addon di firefox che lo fa). Così vedi come è fatto veramente il database sqlite.

Non è tempo perso, è una cosa che prima o poi torna comoda.
NON rispondo a domande nei messaggi privati
Bradipao @ Play Store

Offline psicomant

  • Utente junior
  • **
  • Post: 95
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    OSX 10.6.5
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #2 il: 24 Novembre 2010, 21:05:04 CET »
0
Si stavo provando anche io a usare SQLite manager per capire cosa ci fosse di sbagliato, e in effetti non crea la stringa per la colonna enabled...questo e' cio che mi riporta SQLite Manager:

Codice: [Seleziona]
CREATE TABLE sensors (_id integer primary key autoincrement, sensorid integer not null, sensorname text not null, minsensingfreq integer not null)
mi chiedo perche' non aggiunga quella stringa...e' per caso una stringa che gia viene usata per altri scopi?

Offline Qlimax

  • Moderatore globale
  • Utente senior
  • *****
  • Post: 757
  • Respect: +203
    • Google+
    • _Qlimax
    • Mostra profilo
    • www.egsolutions.ch
  • Dispositivo Android:
    Galaxy Nexus - Nexus One - Wildfire - Magic
  • Play Store ID:
    egsolutions.ch
  • Sistema operativo:
    Ubuntu 12.04, Windows 7
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #3 il: 24 Novembre 2010, 21:31:10 CET »
0
per provare,
fai un
Codice: [Seleziona]
DROP TABLE sensors;prima del create table.

dopo aver provato toglilo

Offline psicomant

  • Utente junior
  • **
  • Post: 95
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    OSX 10.6.5
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #4 il: 24 Novembre 2010, 21:47:38 CET »
0
Ho aggiunto il drop cosi:
Codice (Java): [Seleziona]
                @Override
                public void onCreate(SQLiteDatabase db) {
                       
                        db.execSQL("DROP TABLE" + SENSORS_TABLE);
                        db.execSQL(CREATE_SENSOR_DATABASE);
                       
                        Log.v(TAG, "onCreate");
                }

ora il messaggio d'errore diventa:
Codice: [Seleziona]
11-24 21:45:42.522: ERROR/Database(4745): Failure 1 (near "TABLEsensors": syntax error) on 0x246318 when preparing 'DROP TABLEsensors'.
11-24 21:45:42.562: DEBUG/AndroidRuntime(4745): Shutting down VM
11-24 21:45:42.562: WARN/dalvikvm(4745): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745): FATAL EXCEPTION: main
11-24 21:45:42.612: ERROR/AndroidRuntime(4745): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.CSAMS/com.CSAMS.generalSettings}: android.database.sqlite.SQLiteException: near "TABLEsensors": syntax error: DROP TABLEsensors
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.ActivityThread.startActivityNow(ActivityThread.java:2503)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.LocalActivityManager.moveToState(LocalActivityManager.java:127)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.LocalActivityManager.startActivity(LocalActivityManager.java:339)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.widget.TabHost$IntentContentStrategy.getContentView(TabHost.java:651)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.widget.TabHost.setCurrentTab(TabHost.java:323)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.widget.TabHost$2.onTabSelectionChanged(TabHost.java:129)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.widget.TabWidget$TabClickListener.onClick(TabWidget.java:453)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.view.View.performClick(View.java:2408)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.view.View$PerformClick.run(View.java:8816)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.os.Handler.handleCallback(Handler.java:587)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.os.Looper.loop(Looper.java:123)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.ActivityThread.main(ActivityThread.java:4627)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at java.lang.reflect.Method.invokeNative(Native Method)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at java.lang.reflect.Method.invoke(Method.java:521)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at dalvik.system.NativeStart.main(Native Method)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745): Caused by: android.database.sqlite.SQLiteException: near "TABLEsensors": syntax error: DROP TABLEsensors
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.CSAMS.DBAdapterSensors$DatabaseHelper.onCreate(DBAdapterSensors.java:60)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.CSAMS.DBAdapterSensors.open(DBAdapterSensors.java:80)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.CSAMS.generalSettings.fillSensorsSpinner(generalSettings.java:108)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at com.CSAMS.generalSettings.onCreate(generalSettings.java:48)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
11-24 21:45:42.612: ERROR/AndroidRuntime(4745):     ... 18 more

ora provo a toglierlo?

Offline psicomant

  • Utente junior
  • **
  • Post: 95
  • Respect: 0
    • Mostra profilo
  • Sistema operativo:
    OSX 10.6.5
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #5 il: 24 Novembre 2010, 21:57:41 CET »
0
ok, mettendo DROP TABLE, compilando ed eseguendo  e poi togliendo DROP TABLE, compilando ed eseguendo, riesco ad aggiungere il nuovo campo:
Codice: [Seleziona]
CREATE TABLE sensors (_id INTEGER PRIMARY KEY AUTOINCREMENT, sensorid INTEGER NOT NULL, sensorname TEXT NOT NULL, minsensingfreq INTEGER NOT NULL, mario BOOL NOT NULL DEFAULT 0)

ora pero mi si e' spostato l'errore su un Cursor.  :'(

Vabbe' ma non voglio andare off-topic! :P

Quindi qui saluto tutti e grazie mille!

Offline neo2284

  • Nuovo arrivato
  • *
  • Post: 21
  • Respect: 0
    • Mostra profilo
Re:[android.database.sqlite.SQLiteException: no such column: enabled]
« Risposta #6 il: 26 Marzo 2011, 16:11:49 CET »
0
Salve,
mi potete dire come posso Tramite ADB estrarre il file del database dal telefono/emulatore? ho appena installato sqLite Manager per Firefox. Va bene o devo prendere qualche altro programma? Cmq attendo una vostra risposta e vi ringrazio anticipatamente.