Android; SQLiteConnection-Objekt für die Datenbank geleakt wurde sogar geschlossen

In meiner Datenbank Helfer, ich habe Sie beide geschlossen, die cursor-und Datenbank-Verbindung, aber immer noch die logcat sagt, es ist ein Leck!

Ich habe diesen code in meinem SQLiteOpenHelper

// Getting all entries from database table wp_posts
public ArrayList<String> getAllPosts() {
    // Open the database
    String path_to_db = context.getDatabasePath(db_name).getPath();
    db = SQLiteDatabase.openDatabase(path_to_db, null, SQLiteDatabase.OPEN_READONLY);

    // Prepare the container array
    ArrayList<String> postsArrayList = new ArrayList<String>();

    // select all posts
    String selectQuery = "SELECT post_title FROM " + wp_posts + " ORDER BY post_title COLLATE NOCASE";
    Cursor c = db.rawQuery(selectQuery, null);

    //Log.e("DataBaseHelper", "getAllPosts => line 205");

    // looping through all rows and adding to list
    while (c.moveToNext()) {
        postsArrayList.add(c.getString(0));
    }

    // when you're done close the cursor
    c.close();

    // ..then close the database
    db.close();

    //Log.e("DataBaseHelper", "getAllPosts => line 218");
    return postsArrayList;
}

Die Logcat log

09-22 21:29:24.617: E/DataBaseHelper(17090): DataBaseHelper => 84
09-22 21:29:24.807: D/dalvikvm(17090): GC_FOR_ALLOC freed 78K, 5% free 2895K/3024K, paused 26ms, total 28ms
09-22 21:29:24.807: W/SQLiteConnectionPool(17090): A SQLiteConnection object for database 
                    '/data/data/net.example/databases/atest.db' was leaked!  
                    Please fix your application to end transactions in progress properly and to close 
                    the database when it is no longer needed.
09-22 21:29:24.947: D/dalvikvm(17090): GC_FOR_ALLOC freed 65K, 4% free 3343K/3460K, paused 1ms, total 2ms
09-22 21:29:25.027: E/DataBaseHelper(17090): DataBaseHelper => 88

In der Haupttätigkeit nenne ich die Helfer mit:

    public void fillListView(ListView listview, DataBaseHelper db) {
        Log.e("DataBaseHelper", "DataBaseHelper => 84");

        // Get the entries from db table; wp_posts
        ArrayList<String> entries = db.getAllPosts();
        Log.e("DataBaseHelper", "DataBaseHelper => 88");

        // ..then close the database
        db.close();

        // ArrayAdapter points to list_view.xml; which doesn't contain
        // LinearLayout
        // but only a TextView. This will be used as adapter
        adapter = new ArrayAdapter<String>(this, R.layout.db_row_textview, entries);

        // Binds the Adapter to the ListView
        listview.setAdapter(adapter);

        // Close DB
        db.close();

    }

Was mache ich falsch?
Danke.

InformationsquelleAutor numediaweb | 2013-10-04
Schreibe einen Kommentar