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 9066759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:47:34+00:00 2026-06-16T16:47:34+00:00

Very new to android and have just done a database tutorial and run into

  • 0

Very new to android and have just done a database tutorial and run into the following issues. can anyone see any blinding issues to get me on my way to fixing this?

Heres my three classes:

first class is the main activity class:

package com.example.sqlite;



import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;

public class MainActivity extends ListActivity {

private DBAdapter mDBHelper;
private static final int REQUEST_ADD = 1;
private static final int REQUEST_EDIT = 2;
private Cursor mC;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


mDBHelper = new DBAdapter(this);
mDBHelper = mDBHelper.open();

refreshList();
registerForContextMenu(getListView());


}
// Option menu first
@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate (R.menu.mymenu, menu);
    return true;

}
@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch(item.getItemId())
    {


    case R.id.miAdd:
        Intent i = new Intent ();
        i.setClass(this, Input.class);
        i.putExtra(DBAdapter.COL_ID, 0);
        startActivityForResult(i, REQUEST_ADD);
        return true;

    case R.id.miClear:

    mDBHelper.deleteAllBookmark();
    refreshList();
    return true;

    default:
    return super.onOptionsItemSelected(item);
}
}

@Override
public boolean onContextItemSelected(MenuItem item) {

    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    int position = info.position;
    long id = info.id;
    switch(item.getItemId())
    {

    case R.id.miEdit:

        Cursor c = mC;
        c.moveToPosition(position);


        Intent i  = new Intent();
        i.setClass(this, Input. class);
        i.putExtra(DBAdapter.COL_ID, id);
        i.putExtra(DBAdapter.COL_TITLE, c.getString(c.getColumnIndexOrThrow(DBAdapter.COL_TITLE)));
        i.putExtra(DBAdapter.COL_URL, c.getString(c.getColumnIndexOrThrow(DBAdapter.COL_URL)));

        startActivityForResult(i, REQUEST_EDIT);
        return true;


    case R.id.miDelete:
        mDBHelper.deleteBookmark(id);
        refreshList();
        return true;

        default:
        return super.onContextItemSelected(item);
    }
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
        ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

MenuInflater inflater = getMenuInflater();

inflater.inflate(R.menu.contextmenu, menu);


}
private void refreshList() 
{
    mC = mDBHelper.GetAllBookmarks();
    startManagingCursor(mC);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.row,
            mC, new String[] {DBAdapter.COL_TITLE,DBAdapter.COL_URL},
            new int[] {R.id.txtText1, R.id.txtText2});

    setListAdapter(adapter);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    switch(requestCode)

    {
    case REQUEST_ADD:

        String url = data.getStringExtra(DBAdapter.COL_URL);
        String title = data.getStringExtra(DBAdapter.COL_TITLE);
        mDBHelper.createBookmark(title, url);
        refreshList();
        break;

    case REQUEST_EDIT:

        String editUrl = data.getStringExtra(DBAdapter.COL_URL);
        String editTitle = data.getStringExtra(DBAdapter.COL_TITLE);
        long updateId = data.getLongExtra(DBAdapter.COL_ID, 0);

        mDBHelper.updateBookmark(updateId, editTitle, editUrl);

        break;

        default:

            super.onActivityResult(requestCode, resultCode, data);
    }

}

}

2nd class is the Database adapter class:

package com.example.sqlite;

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

public class DBAdapter {

private static final String DB_NAME = "Bookmark";
private static final String DB_TABLE = "Bookmark";
private static final int DB_VERSION = 1;



private static final String DB_CREATE = 
        "CREATE TABLE Bookmark (" +
        "_id integer PRIMARY KEY AUTOINCREMENT," + 
        "Title text," +
        "url text);";

private static final String DB_UPGRADE = "DROP TABLE IF EXCISTS Bookmark";


public static final String COL_TITLE = "Title";
public static final String COL_URL = "url";
public static final String COL_ID = "id";

private SQLiteDatabase mDB;
private DBHelper mDBHelper;
private Context mCtx;


private static class DBHelper extends SQLiteOpenHelper
{
    public DBHelper (Context context)
    {

        super (context, DB_NAME, null, DB_VERSION);

    }



public void onCreate(SQLiteDatabase db)
{

    db.execSQL(DB_CREATE);


}

public void onUpgrade(SQLiteDatabase db, int newVersion, int oldVersion)
{

    db.execSQL(DB_UPGRADE);

}


}


public DBAdapter(Context ctx)
{
    mCtx = ctx;
}

public DBAdapter open()
{
    mDBHelper = new DBHelper(mCtx);
    mDB = mDBHelper.getWritableDatabase();
    return this;
}

public DBAdapter close()
{
    mDBHelper.close();
    return this;
}

public long createBookmark(String title, String url)
{
    ContentValues v = new ContentValues();
    v.put(COL_TITLE, title);
    v.put(COL_URL, url);
    return mDB.insert(DB_TABLE, null, v);
}

public boolean deleteBookmark(long id)
{
    return mDB.delete(DB_TABLE, COL_ID + "=" + id, null)>0;

}

public boolean deleteAllBookmark()
{
    return mDB.delete(DB_TABLE,null,null)>0;
}


public Cursor GetAllBookmarks()
{
    return mDB.query(DB_TABLE, 
                    new String[] {COL_ID, COL_TITLE, COL_URL}, 
                    null, null, null, null, null);
}

public Cursor GetBookmark(long id)

{
    Cursor mCursor = mDB.query(true, DB_TABLE,
            new String[] {COL_ID, COL_TITLE, COL_URL},
            COL_ID + "=" + id,
            null, null, null, null, null);
    if (mCursor != null)

        mCursor.moveToFirst();
        return mCursor;

}


public boolean updateBookmark(long id, String title, String url)
{
    ContentValues v = new ContentValues();
    v.put(COL_TITLE, title);
    v.put(COL_URL, url);
    return mDB.update(DB_TABLE, v, COL_ID + "=" + id, null)>0;

}



}

The 3rd class is the input class:

package com.example.sqlite;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Input extends Activity {

private EditText txtTitle;
private EditText txtURL;
private Button btnOK;
private long id;
private boolean bUpdateMode = false;

protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);


    setContentView(R.layout.input);


    txtTitle = (EditText) findViewById(R.id.txtTitle);
    txtURL = (EditText) findViewById(R.id.txtURL);
    btnOK = (Button) findViewById(R.id.btnOK);

    Intent i = this.getIntent();

    id = i.getLongExtra(DBAdapter.COL_ID, 0);



    if (id == 0)
    {
        bUpdateMode = false;
    }

    else
    {
        bUpdateMode = true;
        String title = i.getStringExtra(DBAdapter.COL_TITLE);
        String url = i.getStringExtra(DBAdapter.COL_URL);
        txtTitle.setText(title);
        txtURL.setText(url);

    }

    btnOK.setOnClickListener(new View.OnClickListener() 
    {

        public void onClick (View V) 
        {
            Intent i = new Intent ();
            i.putExtra(DBAdapter.COL_URL,    txtURL.getText().toString());
            i.putExtra(DBAdapter.COL_TITLE,  txtTitle.getText().toString());

            if(bUpdateMode)
                i.putExtra(DBAdapter.COL_ID,  id);

            setResult(RESULT_OK, i);
            finish();
        }
    });
}

}       

Logcat:

12-26 18:25:20.360: I/Database(271): sqlite returned: error code = 1, msg = no such   column: id
12-26 18:25:20.379: D/AndroidRuntime(271): Shutting down VM
12-26 18:25:20.379: W/dalvikvm(271): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
12-26 18:25:20.419: E/AndroidRuntime(271): FATAL EXCEPTION: main
12-26 18:25:20.419: E/AndroidRuntime(271): java.lang.RuntimeException: Unable to start   activity ComponentInfo{com.example.sqlite/com.example.sqlite.MainActivity}:   android.database.sqlite.SQLiteException: no such column: id: , while compiling: SELECT id,  Title, url FROM Bookmark
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.os.Looper.loop(Looper.java:123)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread.main(ActivityThread.java:4627)
12-26 18:25:20.419: E/AndroidRuntime(271):  at java.lang.reflect.Method.invokeNative(Native Method)
12-26 18:25:20.419: E/AndroidRuntime(271):  at java.lang.reflect.Method.invoke(Method.java:521)
12-26 18:25:20.419: E/AndroidRuntime(271):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 18:25:20.419: E/AndroidRuntime(271):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 18:25:20.419: E/AndroidRuntime(271):  at dalvik.system.NativeStart.main(Native Method)
12-26 18:25:20.419: E/AndroidRuntime(271): Caused by: android.database.sqlite.SQLiteException: no such column: id: , while compiling: SELECT id, Title, url FROM Bookmark
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:46)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1345)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1229)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1184)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1264)
12-26 18:25:20.419: E/AndroidRuntime(271):  at com.example.sqlite.DBAdapter.GetAllBookmarks(DBAdapter.java:105)
12-26 18:25:20.419: E/AndroidRuntime(271):  at com.example.sqlite.MainActivity.refreshList(MainActivity.java:141)
12-26 18:25:20.419: E/AndroidRuntime(271):  at com.example.sqlite.MainActivity.onCreate(MainActivity.java:33)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
12-26 18:25:20.419: E/AndroidRuntime(271):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
12-26 18:25:20.419: E/AndroidRuntime(271):  ... 11 more
12-26 18:25:32.789: I/Process(271): Sending signal. PID: 271 SIG: 9
  • 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-06-16T16:47:35+00:00Added an answer on June 16, 2026 at 4:47 pm
    SQLiteException: no such column: id: , while compiling: SELECT id,  Title, url FROM Bookmark
    

    You are trying to select "id" but your column is named "_id":

    private static final String DB_CREATE = 
            "CREATE TABLE Bookmark (" +
            "_id integer PRIMARY KEY AUTOINCREMENT," + 
            "Title text," +
            "url text);";
    

    You need to change COL_ID to include the underscore:

    public static final String COL_ID = "_id";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before I delve into it, I'm very new to Android and I have just
I am writing an Android app and have run into a very strange situation.
Im very new to android/java and have been following a few youtube tutorials and
i am very new to the android app development, and i have just almost
I am very new to Android development and Java. Have read around but I'm
I'm following the android developer tutorials on tab layouts. (im very very new to
Very new to python and can't understand why this isn't working. I have a
I have been slowing learning and building my first android app. I'm VERY new
I have just started Android development. I have a very simple project. I have
I'm very new to Java and the Android SDK but I'm almost done with

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.