首页 > 解决方案 > 在 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();

        }
    });

标签: androidsqlitefetch

解决方案


在我看来,您没有在 logcat 中检查正确的日志,因为您已经 qouted 是调试日志,请将您的 logcat 更改为 info 并在使用 , 写入 info 日志时检查Log.i()

您看到的日志可能是由相同操作触发的其他一些调试日志。在此处查看以了解有关 logcat 的更多信息。


推荐阅读