Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SQLiteDatabase Query SQL Logic Error or Missing Database
    primarykey
    data
    text
    <p>So I created a database using SQLiteOpenHelper and I'm trying to query it. It returns the cursor but when I call moveToFirst() it crashes with the error <code>SQL Logic Error or Missing Database.</code> </p> <p>I follow this websites code to create and query my database: <a href="http://www.vogella.de/articles/AndroidSQLite/article.html" rel="nofollow">http://www.vogella.de/articles/AndroidSQLite/article.html</a></p> <p>EDIT:</p> <p>My Database:</p> <pre><code>public class Database{ private static final String DATABASE_NAME = "MyDatabase"; private static final int DATABASE_VERSION = 1; private static final String TABLE_NAME = "MyTable"; // Column Names public static final String ID = "_id"; // INTEGER public static final String NUMBER = "number"; // TEXT private SQLiteDatabase database; private DatabaseHelper mDatabaseOpenHelper; public Database(Context context){ mDatabaseOpenHelper = new DatabaseHelper(context); database = mDatabaseOpenHelper.getWritableDatabase(); } public void close(){ database.close(); } public long addNumber(String number){ ContentValues values = new ContentValues(); values.put(NUMBER, number); return database.insert(TABLE_NAME, null, values); } public Cursor getNumber(String number){ String selection = NUMBER + " MATCH ?"; String[] selectionArgs = new String[] {number}; return database.query(TABLE_NAME, null, selection, selectionArgs, null, null, null); } private class DatabaseHelper extends SQLiteOpenHelper{ private static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + "(_id INTEGER PRIMARY KEY AUTOINCREMENT, " + NUMBER + " TEXT)"; public DatabaseHelper(Context context){ super(context, DATABASE_NAME, null, DATABASE_VERSION); } public void onCreate(SQLiteDatabase db) { db.execSQL(CREATE_TABLE); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME); onCreate(db); } } } </code></pre> <p>And this is how I query:</p> <pre><code> Database database = new Database(this); Cursor cursor = database.getTrUpdate("1234"); if (cursor.moveToFirst()){ do{ int d = cursor.getInt(cursor.getColumnIndex(Database.ID)); } while(cursor.moveToNext()); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload