简体   繁体   中英

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

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);

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM