android - 在 logcat 中从 Sqlite android 检索数据
问题描述
我编写了以下代码来从我的数据库中检索数据并在日志窗口中显示所有找到的对象,但它没有显示..help?
public void afisareOferta() throws Exception {
String selectQuery = " SELECT * FROM " + DBConst.tabela;
Cursor cursor = db.rawQuery(selectQuery,null);
String result;
if(cursor.moveToFirst()) {
do {
//HomeExchange hm = new HomeExchange();
result = cursor.getString(0) + cursor.getString(1) + cursor.getString(2) + cursor.getString(3 ) + cursor.getString(4);
/* hm.setLocalitatea(cursor.getString(0));
hm.setTipLocuinta(cursor.getString(1));
hm.setNrCamere(cursor.getInt(2));
hm.setData(cursor.getString(3));
hm.setDurata(cursor.getInt(4));*/
Log.i("Citire din bd:", result);
}
while (cursor.moveToNext());
}
}
日志猫:
07-02 20:57:53.933 1969-1969/com.example.colega.restanta20182altfeldeafisaredata D/ViewRootImpl@9a0e50e[MainActivity]: ViewPostIme pointer 0
07-02 20:57:54.001 1969-1969/com.example.colega.restanta20182altfeldeafisaredata D/ViewRootImpl@9a0e50e[MainActivity]: ViewPostIme pointer 1
07-02 20:58:14.594 1969-1969/com.example.colega.restanta20182altfeldeafisaredata D/ViewRootImpl@9a0e50e[MainActivity]: ViewPostIme pointer 0
07-02 20:58:14.699 1969-1969/com.example.colega.restanta20182altfeldeafisaredata D/ViewRootImpl@9a0e50e[MainActivity]: ViewPostIme pointer 1
当我按下以下按钮时,这会出现:
bRead.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
DBAdapter db = new DBAdapter(getApplicationContext());
db.openConnection();
try {
db.afisareOferta();
} catch (Exception e) {
e.printStackTrace();
}
db.closeConnection();
}
});
解决方案
在我看来,您没有在 logcat 中检查正确的日志,因为您已经 qouted 是调试日志,请将您的 logcat 更改为 info 并在使用 , 写入 info 日志时检查Log.i()
。
您看到的日志可能是由相同操作触发的其他一些调试日志。在此处查看以了解有关 logcat 的更多信息。
推荐阅读
- java - 我怎样才能只从 textClock 获得小时
- google-play-console - 成为 Play 管理中心帐号的共同所有者
- c++ - 哪个是初始化数组、“memset”或“{//value}”的最佳方法?
- swift - 如何从 JWT 令牌有效负载中提取日期“exp”
- android - 如果我的应用暂停时间过长,我该如何刷新它
- c# - 背景颜色计时器 Xamarin 表单
- cassandra - “Cassandra 在针对单个分区进行批量突变时提供原子性和隔离性”的含义
- lua - 在游戏对象脚本中调整碰撞对象的形状
- regex - 无法为用户名生成正则表达式
- python - 是否有替代 stats.zscore 来检测数据框中少于 10 行的异常值?