I keep hitting the 'no such table' error for this. I use two very similar database helper classes. The first one works fine with the same implementation, the second one always crashes the app saying that there is no such table! Here is the code for the first table being implemented:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new DatabaseHelper(this);
workoutsCursor = db
.getReadableDatabase()
.rawQuery("SELECT _ID, title " +
"FROM workouts ORDER BY title",
null
);
adapter = new SimpleCursorAdapter(this,
R.layout.list_view_item, workoutsCursor,
new String[]{DatabaseHelper.TITLE},
new int[]{R.id.textViewItem}, 0);
setListAdapter(adapter);
registerForContextMenu(getListView());
}
And the overridden onCreate of that db helper:
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE workouts (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT);");
}
Compare this to the implementation of the second table in the second activity along with its respective dbhelper's onCreate:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nIntent = getIntent();
PID = nIntent.getIntExtra("PID", 0);
String eyedee = Integer.toString(PID);
try {
db = new ExerciseDBHelper(this);
exerciseCursor = db
.getReadableDatabase()
.rawQuery("SELECT _ID, title " +
"FROM exercises WHERE pid = " + eyedee,
null
);
} catch (Exception e){
Log.d("MAKEDB", "that didnt work bruh");
}
adapter = new SimpleCursorAdapter(this,
R.layout.list_view_item, exerciseCursor,
new String[]{ExerciseDBHelper.TITLE},
new int[]{R.id.textViewItem}, 0);
setListAdapter(adapter);
registerForContextMenu(getListView());
and
@Override
public void onCreate(SQLiteDatabase db){
db.execSQL("CREATE TABLE exercises (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, pid INTEGER);");
}
If it helps: This worked as it is before I uninstalled the app and reinstalled it.