从sqlite的收集数据,并在TextView中显示它 [英] Collect data from sqlite and display it in TextView
本文介绍了从sqlite的收集数据,并在TextView中显示它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能提取我感兴趣这样的数据:
I was able to be extracted the data that interest me in this way:
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);
问题是,如果数据库中有数据,一切正常,但如果数据库是空的,应用程序崩溃。
the problem is that if the database has data, everything works, but if the database is empty, the application crashes.
推荐答案
由于给出的这后,试试这个
As given in this post, try this
if ( cursor.moveToFirst() ) {
// start activity a
} else {
// start activity b
}
cursor.moveToFirst()将返回false,如果指针是空的。这对我的作品始终。
cursor.moveToFirst() will return false if the cursor is empty. It works for me always.
您可以尝试在该帖子还给出了第一种方法。
You can try the first method given on that post also.
这篇关于从sqlite的收集数据,并在TextView中显示它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文