Android 从sqlite收集数据并在TextView中显示
我能够通过以下方式提取我感兴趣的数据:Android 从sqlite收集数据并在TextView中显示,android,sqlite,select,Android,Sqlite,Select,我能够通过以下方式提取我感兴趣的数据: Cursor stipcursor = dataBase.rawQuery("SELECT (riepilogo) AS stip FROM "+DbHelper.RIEPILOGO+" WHERE MESI = 'Gennaio' and ANNI = "+anno+"", null); int colIndexstip = stipcursor.getColumnI
Cursor stipcursor = dataBase.rawQuery("SELECT (riepilogo) AS stip FROM "+DbHelper.RIEPILOGO+" WHERE MESI = 'Gennaio' and ANNI = "+anno+"", null);
int colIndexstip = stipcursor.getColumnIndex("stip");
if (colIndexstip == -1)
return;
else
stipcursor.moveToFirst();
double stip = stipcursor.getDouble(colIndexstip);
System.out.println("Riepilogo"+stip);
问题是,如果数据库有数据,一切正常,但如果数据库为空,应用程序就会崩溃。如本文所述,请尝试以下方法
if ( cursor.moveToFirst() ) {
// start activity a
} else {
// start activity b
}
如果光标为空,则cursor.moveToFirst将返回false。这对我总是有用的
你也可以尝试那篇文章中给出的第一种方法。这不是答案,而是观察。将月份存储为字符串月份名称?取而代之的是整数,效率很低。但最后SQLite中的所有内容都是字符串,尽管与答案无关。是的,在数据库中,以字符串形式插入数据,2014年1月。111111111我想提取数字字符串111111111