Hi all,
I am developing an application that need a database (store username
and password) and when I try to access to it I obtain those errors in
the logCat :

05-07 09:02:17.194: ERROR/AndroidRuntime(520): Uncaught handler:
thread main exiting due to uncaught exception
05-07 09:02:17.213: ERROR/AndroidRuntime(520):
android.database.sqlite.SQLiteException: no such table: options: ,
while compiling: SELECT DISTINCT _id, title, body FROM options WHERE
_id=0
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteProgram.native_compile(Native Method)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:48)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteDirectCursorDriver.query
(SQLiteDirectCursorDriver.java:49)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteDatabase.rawQueryWithFactory
(SQLiteDatabase.java:1017)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteDatabase.queryWithFactory
(SQLiteDatabase.java:905)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:863)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.application.MonkeySMS.OptionDb.fetchOption(OptionDb.java:
84)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.application.MonkeySMS.Option$1.onClick(Option.java:70)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.View.performClick(View.java:2129)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.View.onTouchEvent(View.java:3543)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.widget.TextView.onTouchEvent(TextView.java:4664)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.View.dispatchTouchEvent(View.java:3198)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:857)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.superDispatchTouchEvent(PhoneWindow.java:1593)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent
(PhoneWindow.java:1089)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.app.Activity.dispatchTouchEvent(Activity.java:1871)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.internal.policy.impl.PhoneWindow
$DecorView.dispatchTouchEvent(PhoneWindow.java:1577)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.view.ViewRoot.handleMessage(ViewRoot.java:1140)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.os.Handler.dispatchMessage(Handler.java:88)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.os.Looper.loop(Looper.java:123)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
android.app.ActivityThread.main(ActivityThread.java:3739)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
java.lang.reflect.Method.invokeNative(Native Method)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
java.lang.reflect.Method.invoke(Method.java:515)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run
(ZygoteInit.java:739)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:497)
05-07 09:02:17.213: ERROR/AndroidRuntime(520):     at
dalvik.system.NativeStart.main(Native Method)

The problem appends when the program arrives at this line in my
program :

if(mOptionDb.fetchOption(0)==null && mOptionDb.fetchOption(1)==null){
                                mOptionDb.createOption(titleDb0, 
txtUsername.toString
());
                                mOptionDb.createOption(titleDb1, 
txtPassword.toString
());
                        }

mOptionDb is an OptionDb.

The OptionDb file is the following :

public class OptionDb {

        private Context mCtx;

        public static final String KEY_TITLE = "title";
    public static final String KEY_BODY = "body";
    public static final String KEY_ROWID = "_id";

    private static final String TAG = "OptionDbAdapter";
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDb;

        private static final String DATABASE_CREATE =
        "create table options (_id integer primary key autoincrement,
"
                + "title text not null, body text not null);";

        private static final String DATABASE_NAME = "data";
        private static final String DATABASE_TABLE = "options";
        private static final int DATABASE_VERSION = 2;

        private static class DatabaseHelper extends SQLiteOpenHelper {

        DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {

            db.execSQL(DATABASE_CREATE);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
            Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
                    + newVersion + ", which will destroy all old
data");
            db.execSQL("DROP TABLE IF EXISTS notes");
            onCreate(db);
        }
    }

        public OptionDb(Context ctx) {
                this.mCtx = ctx;
        }

        public OptionDb open() throws SQLException {
                mDbHelper = new DatabaseHelper(mCtx);
        mDb = mDbHelper.getWritableDatabase();
        return this;
        }

        public void close(){
                mDbHelper.close();
        }

        public void createOption(String title, String body) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_BODY, body);

        mDb.insert(DATABASE_TABLE, null, initialValues);
        //return mDb.insert(DATABASE_TABLE, null, initialValues);
    }

    public boolean deleteOption(long rowId) {

        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId,
null) > 0;
    }

    public Cursor fetchOption(long rowId) throws SQLException {

        Cursor mCursor =

                mDb.query(true, DATABASE_TABLE, new String[]
{KEY_ROWID,
                        KEY_TITLE, KEY_BODY}, KEY_ROWID + "=" + rowId,
null,
                        null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }

    public boolean updateOption(long rowId, String title, String body)
{
        ContentValues args = new ContentValues();
        args.put(KEY_TITLE, title);
        args.put(KEY_BODY, body);

        return mDb.update(DATABASE_TABLE, args, KEY_ROWID + "=" +
rowId, null) > 0;
    }

}

I don't know if the problem comes from the way the program access the
database or if database needs permission...
I am a little bit lost.
Thank you for your help.
Michaël

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to