App crashing when I try to populate a list view with a Sql table

107 Views Asked by At

I'm trying to populate a list view with data from a table in SQL via a SimpleCursorAdapter, but every time the activity opens, it crashes the app. Android Studio is not letting me see my error logs for some reason. Can someone please tell me what exactly is wrong with this code? It is inside my onCreate method.

db = openOrCreateDatabase("namesAndscoresAndtimes", SQLiteDatabase.CREATE_IF_NECESSARY, null);
c = db.query("namesAndscoresAndtimes", null, null, null, null, null, null);
String[] fromCols = { "name", "score", "time", "percentile" };
int[] toViews = { R.id.name, R.id.score, R.id.time, R.id.points };
SimpleCursorAdapter sca = new SimpleCursorAdapter(this, R.layout.scr, c, fromCols, toViews, 0);
ListView lv = (ListView) findViewById(R.id.scoretables);
lv.setAdapter(sca);
2

There are 2 best solutions below

0
On

never mind my table needed a _id column in order to use a SimpleCursorAdapter on it. So i ended up making a new database (i could have just made a new table instead, also).

1
On

may be you wrong at,

c = db.query("namesAndscoresAndtimes", null, null, null, null, null, null);

the first parameter is a table name not the database name