I'd like to use an sqlite database for my android application.First question, do I need to have a rooted device?! If i try adb shell sqlite3 on my Galaxy S, it will return "not found" error. Also, when I try to "ls /data/ " i get "No permission" error.
Second question, the NullPointer itself.
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): Caused by: java.lang.NullPointerException
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:98)
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): at com.gpachov.priorityqueue.database.Database.getAllRecords(Database.java:24)
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): at com.gpachov.priorityqueue.database.DatabaseAdapter.<init>(DatabaseAdapter.java:21)
07-23 10:58:17.546: ERROR/AndroidRuntime(12815): at com.gpachov.priorityqueue.PriorityQueueActivity.<init>(PriorityQueueActivity.java:20)
It happens in the Context itself when trying to access the database.
Here is my code.
public class DatabaseHelper extends SQLiteOpenHelper {
private final static String DATABASE_NAME="queue";
private final static int DATABASE_VERSION = 1;
public DatabaseHelper(Context context){
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(ItemTable.CREATE_STRING);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//nothing for now
}
}
And the more important null pointer causing class:
public class Database {
private DatabaseHelper mDatabaseHelper;
public Database(Context context) {
mDatabaseHelper = new DatabaseHelper(context);
}
List<Item> getAllRecords() {
final SQLiteDatabase database = mDatabaseHelper.getReadableDatabase();
.................
It blows with the NPE on the first line of getAllRecords().
Oh yeah, and here is my create string:
public static final String CREATE_STRING = "create table items (id integer primary key autoincrement, "+ "title text not null, description text not null, priority integer not null)";