I get an error and i can't fix it. Error is SQLiteLog (1) I got it from a tutorial from bucky nr 53. Other message i got is: ClassLoader referenced unknown path: /data/app/com.example.jeroe.examenapp-2/lib/arm64 but i dont know if thats where the bug is.
package com.example.jeroe.examenapp;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.Cursor;
import android.content.Context;
import android.content.ContentValues;
public class MyDBHandler extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1; //version
private static final String DATABASE_NAME = "vakken.db"; //name of the file
public static final String TABLE_VAKKEN = "vakken"; //name of your table
public static final String COLUMN_ID = "_id"; //name for every
public static final String COLUMN_VAKNAME = "_vakname";
public MyDBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, DATABASE_NAME, factory, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_VAKKEN + "(" +
COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT " +
COLUMN_VAKNAME + " TEXT " + ");";
db.execSQL(query); //execute db and wich one (so query in this instance)
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_VAKKEN);
onCreate(db);
}
//Print out database as a string
public String databaseToString(){
String dbString = "";
SQLiteDatabase db = getWritableDatabase();
String query = "SELECT * FROM " + TABLE_VAKKEN + " WHERE 1";
//Cursor point to a location in your results
Cursor c = db.rawQuery(query, null);
//move to the first row in your results
c.moveToFirst();
while(!c.isAfterLast()){
if(c.getString(c.getColumnIndex("vakname")) != null){
c.moveToNext();
dbString += c.getString(c.getColumnIndex("vakname"));
dbString += "\n";
}
}
c.close();
db.close();
return dbString;
}
}
Aucun commentaire:
Enregistrer un commentaire