Sqlite数据库操作在stacktrace中显示“table name = null”

时间:2013-04-29 05:17:20

标签: android sqlite

我是Android操作系统的新手。我开发了一个运行良好的应用程序。但是在logcat中我总是得到以下几行。

04-29 10:21:44.263: D/Cursor(2101): Database path: mydb
04-29 10:21:44.263: D/Cursor(2101): Table name   : null

我想知道为什么这些行会出现在logcat中。难道我做错了什么?以下是我用于我的应用程序的代码。

 public ArrayList<LD> fetchData() {
    String C="c",query;
    Cursor mCursor = null;
    LD lData = null;
    ArrayList<LD> myData = new ArrayList<LD>();
    try{ 
        openDBConnection(); //open database

        query = "SELECT * FROM ANDROID_DATA WHERE STATUS = '" + C +"';";
        mCursor = database.rawQuery(query, null);

        if (mCursor.moveToFirst()) {
            do{
                lData = new LD();
                String id = mCursor.getString(0);
                lData.setId(Integer.parseInt(id));
                lData.setFName(mCursor.getString(1));
                lData.setLName(mCursor.getString(2));

                java.util.Date ct = new java.util.Date(mCursor.getLong(3));                 
                lData.setCreatedTime(ct);

                myData.add(lData);                      
            } while(mCursor.moveToNext());
        }
    } catch(Exception e) {
        //TODO: Handle Excaption
    } finally {
        closeDBConnection(); //close database
    }
    return myData;  
} 

1 个答案:

答案 0 :(得分:3)

我认为您缺少关闭光标..在代码中添加以下行... 只需在finally块中关闭光标..

public ArrayList<LD> fetchData() {
    String C="c",query;
    Cursor mCursor = null;
    LD lData = null;
    ArrayList<LD> myData = new ArrayList<LD>();
    try{ 
        openDBConnection(); //open database

        query = "SELECT * FROM ANDROID_DATA WHERE STATUS = '" + C +"';";
        mCursor = database.rawQuery(query, null);

        if (mCursor.moveToFirst()) {
            do{
                lData = new LD();
                String id = mCursor.getString(0);
                lData.setId(Integer.parseInt(id));
                lData.setFName(mCursor.getDouble(1));
                lData.setLName(mCursor.getDouble(2));

                java.util.Date ct = new java.util.Date(mCursor.getLong(4));                 
                lData.setCreatedTime(ct);

                myData.add(locData);                        
            } while(mCursor.moveToNext());
        }
    } catch(Exception e) {
        //TODO: Handle Excaption
    } finally {
        try{
            if (mCursor != null ) {
                mCursor.close();
            }
        }catch(Exception e){}
        closeDBConnection(); //close database
    }
    return myData;  
}

希望这对你有用..