简体   繁体   English

当我尝试使用Sql表填充列表视图时,应用崩溃

[英]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. 我试图通过SimpleCursorAdapter用SQL中的表中的数据填充列表视图,但是每次活动打开时,应用程序都会崩溃。 Android Studio is not letting me see my error logs for some reason. 由于某些原因,Android Studio不允许我查看错误日志。 Can someone please tell me what exactly is wrong with this code? 有人可以告诉我这段代码到底有什么问题吗? It is inside my onCreate method. 它在我的onCreate方法中。

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 第一个参数是table name而不是database name

never mind my table needed a _id column in order to use a SimpleCursorAdapter on it. 没关系,我的表需要_id列才能在其上使用SimpleCursorAdapter。 So i ended up making a new database (i could have just made a new table instead, also). 因此,我最终创建了一个新数据库(我也可以只创建一个新表)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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