Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7662761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:53:01+00:00 2026-05-31T13:53:01+00:00

I’m trying to feed a listview with a custom cursorAdapter. I get this error

  • 0

I’m trying to feed a listview with a custom cursorAdapter.

I get this error : 03-16 03:25:39.968: E/AndroidRuntime(14552): Caused by: android.database.sqlite.SQLiteException: no such column: _id: , while compiling: SELECT _id, content_note FROM notes

at this line values.put(DataBaseHelper.DATABASEBASE_CONTENT_NOTE, note.getContent());

Here are my 2 Connections classes

    package com.android.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DataBaseHelper extends SQLiteOpenHelper{

    private static final String DATABASE_NAME = "db";
    public static final String DATABASE_TABLE_NOTE = "notes";
    public static final String DATABASE_ID_NOTE = "_id";
    public static final String DATABASE_CONTENT_NOTE = "content_note";

    public DataBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE " + DATABASE_TABLE_NOTE + " (" + DATABASE_ID_NOTE + " INTEGER PRIMARY KEY, " + DATABASE_CONTENT_NOTE + " TEXT);");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        android.util.Log.w("Constants", "Maj de la base, suppression de toutes les anciennes donnees");
        db.execSQL("DROP TABLE IF EXISTS Notes");
        onCreate(db);
    }

}



    package com.android.database;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

public class NoteDataSource{

    private SQLiteDatabase database;
    private DataBaseHelper dbHelper;
    private String[] allColumns = { DataBaseHelper.DATABASE_ID_NOTE,
            DataBaseHelper.DATABASE_CONTENT_NOTE };

    public NoteDataSource(Context context) {
        dbHelper = new DataBaseHelper(context);
    }


    public void open() throws SQLException {
        database = dbHelper.getWritableDatabase();
    }

    public void close() {
        dbHelper.close();
    }

    public Cursor createNoteTop(String note) {

        //recuperer le bon id

//      int idNote = getFirstId().getId();
        int idNote = 1 ;

        ContentValues values = new ContentValues();
        values.put(DataBaseHelper.DATABASE_ID_NOTE, idNote);
        values.put(DataBaseHelper.DATABASE_CONTENT_NOTE, note);
        long insertId = database.insert(DataBaseHelper.DATABASE_TABLE_NOTE, null,
                values);
        Cursor cursor = database.query(DataBaseHelper.DATABASE_TABLE_NOTE,
                allColumns, DataBaseHelper.DATABASE_ID_NOTE + " = " + insertId, null,
                null, null, null);
        cursor.moveToFirst();
        return cursor;
    }

    public Cursor createNoteBottom(String note) {

        //recuperer le bon id

        int idNote = getLastId().getId();

        ContentValues values = new ContentValues();
        values.put(DataBaseHelper.DATABASE_ID_NOTE, idNote);
        values.put(DataBaseHelper.DATABASE_CONTENT_NOTE, note);
        long insertId = database.insert(DataBaseHelper.DATABASE_TABLE_NOTE, null,
                values);
        // To show how to query
        Cursor cursor = database.query(DataBaseHelper.DATABASE_TABLE_NOTE,
                allColumns, DataBaseHelper.DATABASE_ID_NOTE + " = " + insertId, null,
                null, null, null);
        cursor.moveToFirst();
        return cursor;
    }

    public void deleteNote(Note note) {
        long id = note.getId();
        System.out.println("Note deleted with id: " + id);
        database.delete(DataBaseHelper.DATABASE_TABLE_NOTE, DataBaseHelper.DATABASE_ID_NOTE
                + " = " + id, null);
    }

    public Cursor getAllNotes() {
        Cursor cursor = database.query(DataBaseHelper.DATABASE_TABLE_NOTE,
                allColumns, null, null, null, null, null);
        return cursor;
    }

    private Note getFirstId(){
        Note notes = new Note();
        Cursor cursor = database.query(DataBaseHelper.DATABASE_TABLE_NOTE,
                allColumns, null, null, null, null, null);
        cursor.moveToFirst();
        notes = cursorToNote(cursor);

        return notes;

    }

    private Note getLastId(){

        Note notes = new Note();
        Cursor cursor = database.query(DataBaseHelper.DATABASE_TABLE_NOTE,
                allColumns, null, null, null, null, null);
        cursor.moveToLast();
        notes = cursorToNote(cursor);

        return notes;

    }

    private Note cursorToNote(Cursor cursor) {
        Note note = new Note();
        note.setId(cursor.getInt(0));
        note.setContent(cursor.getString(1));
        return note;
    }




}

This must be simple and come from the fact that I already created base with other name fields and it doesn’t upgrade.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:53:03+00:00Added an answer on May 31, 2026 at 1:53 pm

    This must be simple and come from the fact that I already created base with other name fields and it doesn’t upgrade.

    I guess you are right. You should increase the version number whenever you change the database. Then you can put code in onUpgrade that can handle the transition.

    private static final int DATABASE_VERSION = 2;
    public DataBaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    

    The schema for onUpgrade is usually like this

    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // it all started this way
        if (oldVersion < 1) {
            db.execSQL("CREATE TABLE supertable...");
        }
    
        // in version 2 I decided that I need another table
        if (oldVersion < 2) {
            db.execSQL("CREATE TABLE cooltable...");
        }
    
        // in version 3 I decided that the table is not required anymore
        if (oldVersion < 3) {
            db.execSQL("DROP TABLE cooltable...");
        }
        // remember to increase DATABASE_VERSION if you add steps here.
    }
    

    That upgrade schema will also allow users that have your app installed to upgrade the app to new versions without getting corrupted databases.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.