Android:SQLite,cursor.moveToNext()始终返回false

以下语句cursor.movetoNext()始终为false.我希望循环执行一次.我已经测试过查询实际返回的数据.

有谁知道是什么事吗?

String query ="SELECT(SELECT COUNT(*) FROM Table1) as count1,(SELECT COUNT(*) FROM Table2) as count2;";

    Cursor mCursor = mDb.rawQuery(query,null);

    if (mCursor != null) {
        mCursor.movetoFirst();
    }

    while (cursor.movetoNext()) {   //<---------------return false here???
        String result_0=cursor.getString(0);
    }

解决方法

@H_404_9@ 我知道你已经解决了你的问题,但这是对发生的事情的一个演练:
Cursor mCursor = mDb.rawQuery(query,null);

// At this point mCursor is positioned at just before the first record.

if (mCursor != null) {
    mCursor.movetoFirst();
    // mCursor is Now pointing at the first (and only) record
}

while (mCursor.movetoNext()) {
    String result_0=cursor.getString(0);
}

// The loop above was skipped because `.movetoNext()` caused mCursor
// to move past the last record.

因此,在您只需要一条记录的情况下,您只需要mCursor.movetoFirst()或您的mCursor.movetoNext().

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...