在Android设备上运行时,数据库变为空,没有行

时间:2013-06-15 16:19:00

标签: android sqlite listview

你好我在模拟器上运行我的应用程序时有一个奇怪的问题它工作正常并在列表视图中显示数据库中的所有公司名称,但是当我在真实设备上运行它时数据库变空而没有行。(cursor.getCount()返回0)..我不知道为什么会发生这种情况!提前致谢

我的logcat:

06-15 18:56:23.031: D/dalvikvm(9213): GC_FOR_ALLOC freed 77K, 3% free 12870K/13191K, paused 30ms
06-15 18:56:23.066: D/dalvikvm(9213): GC_FOR_ALLOC freed 109K, 4% free 12954K/13447K, paused 26ms
06-15 18:56:23.066: I/dalvikvm-heap(9213): Grow heap (frag case) to 13.093MB for 262160-byte allocation
06-15 18:56:23.086: D/dalvikvm(9213): GC_FOR_ALLOC freed <1K, 5% free 13210K/13767K, paused 13ms
06-15 18:56:23.106: D/dalvikvm(9213): GC_FOR_ALLOC freed 0K, 5% free 13210K/13767K, paused 17ms
06-15 18:56:23.106: I/dalvikvm-heap(9213): Grow heap (frag case) to 13.537MB for 465140-byte allocation
06-15 18:56:23.126: D/dalvikvm(9213): GC_CONCURRENT freed 0K, 5% free 13664K/14279K, paused 1ms+1ms
06-15 18:56:23.161: D/dalvikvm(9213): GC_FOR_ALLOC freed 256K, 7% free 13409K/14279K, paused 13ms
06-15 18:56:23.161: I/dalvikvm-heap(9213): Grow heap (frag case) to 13.743MB for 476816-byte allocation
06-15 18:56:23.181: D/dalvikvm(9213): GC_CONCURRENT freed <1K, 7% free 13875K/14791K, paused 1ms+1ms
06-15 18:56:23.261: D/dalvikvm(9213): GC_FOR_ALLOC freed 0K, 7% free 13875K/14791K, paused 32ms
06-15 18:56:23.261: I/dalvikvm-heap(9213): Grow heap (frag case) to 14.550MB for 846420-byte allocation
06-15 18:56:23.286: D/dalvikvm(9213): GC_CONCURRENT freed 0K, 6% free 14702K/15623K, paused 2ms+1ms
06-15 18:56:23.616: D/CLIPBOARD(9213): Hide Clipboard dialog at Starting input: finished by someone else... !
06-15 18:56:36.801: E/yallaaaaaaaaaaaa(9213): 0
06-15 18:56:36.801: I/System.out(9213): count0

1 个答案:

答案 0 :(得分:0)

很久以前我也遇到了类似的问题..

创建一个临时表说temp并从另一个表中插入行。

public void populate_temp() 
{

dbsqlite.execSQL("delete from temp");
dbsqlite.execSQL(" insert into temp(name) select city from City ORDER BY city ASC ");

}     

然后通过从临时表

中检索值来填充列表
public List<String> getAllLabels() 
{
    List<String> labels = new ArrayList<String>();
    String selectQuery = "select DISTINCT name from temp";
    dbsqlite = this.getReadableDatabase();
    Cursor cursor = dbsqlite.rawQuery(selectQuery, null);

    if (cursor.moveToFirst()) {
        do {
             labels.add(cursor.getString(cursor.getColumnIndex("name")));

        } while (cursor.moveToNext());
    }

    cursor.close();
    dbsqlite.close();

    return labels;
}

这可能不是一个好的编程习惯,但工作得很好! ;)