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

  • Home
  • SEARCH
  • 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 6365569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:18:35+00:00 2026-05-25T00:18:35+00:00

Hello my favorite help resource… I am a average android programmer making an application

  • 0

Hello my favorite help resource…

I am a average android programmer making an application designed to simply randomly draw a name from an array and display it… The issue in putting this app into a release version is that it needs to have editable strings stored in a database, so I naturally turned to android’s implementation of sql lite. I’ll be honest, I didn’t know the first thing about it up until after looking through the source code of the example I found. I am using a modified version of that example to simply store a name (the string) and the ID of the string… I run into a syntax error, I will display the logcat data later in the question… any other things you may find in my code that may be wrong, or even some tips, would be greatly appreciated…
Here comes the onslaught of code…

peopleDatabaseHelper

package com.b.wom.peopledatabase;

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

public class peopleDatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "applicationdata";

    private static final int DATABASE_VERSION = 1;

    // Database creation sql statement
    private static final String DATABASE_CREATE = "create table todo (_id integer primary key autoincrement, "
            + "name text not null);";

    public peopleDatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    // Method is called during creation of the database
    @Override
    public void onCreate(SQLiteDatabase database) {
        database.execSQL(DATABASE_CREATE);
    }

    // Method is called during an upgrade of the database, e.g. if you increase
    // the database version
    @Override
    public void onUpgrade(SQLiteDatabase database, int oldVersion,
            int newVersion) {
        Log.w(peopleDatabaseHelper.class.getName(),
                "Upgrading database from version " + oldVersion + " to "
                        + newVersion + ", which will destroy all old data");
        database.execSQL("DROP TABLE IF EXISTS todo");
        onCreate(database);
    }
}

peopleDbAdapter

    package com.b.wom.peopledatabase;

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

    public class peopleDbAdapter {

        // Database fields
        public static final String KEY_ROWID = "_id";
        public static final String KEY_NAME = "name";
        private static final String DATABASE_TABLE = "table";
        private Context context;
        private SQLiteDatabase database;
        private peopleDatabaseHelper dbHelper;

        public peopleDbAdapter(Context context) {
            this.context = context;
        }

        public peopleDbAdapter open() throws SQLException {
            dbHelper = new peopleDatabaseHelper(context);
            database = dbHelper.getWritableDatabase();
            return this;
        }

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

        /**
         * Create a new todo If the todo is successfully created return the new
         * rowId for that note, otherwise return a -1 to indicate failure.
         */
        public long createPerson(String name) {
            ContentValues initialValues = createContentValues(name);

            return database.insert(DATABASE_TABLE, null, initialValues);
        }

        /**
         * Update the todo
         */
        public boolean updatePerson(long rowId, String name) {
            ContentValues updateValues = createContentValues(name);

            return database.update(DATABASE_TABLE, updateValues, KEY_ROWID + "="
                    + rowId, null) > 0;
        }

        /**
         * Deletes todo
         */
        public boolean deletePerson(long rowId) {
            return database.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
        }

        /**
         * Return a Cursor over the list of all people in the database
         * 
         * @return Cursor over all people
         */
        public Cursor fetchAllPeople() {
            return database.query(DATABASE_TABLE, new String[] { KEY_ROWID,
                    KEY_NAME }, null, null, null, null, null);
        }

        /**
         * Return a Cursor positioned at the defined person
         */
        public Cursor fetchPerson(long rowId) throws SQLException {
            Cursor mCursor = database.query(true, DATABASE_TABLE, new String[] {
                    KEY_ROWID, KEY_NAME }, KEY_ROWID + "=" + rowId, null, null,
                    null, null, null);
            if (mCursor != null) {
                mCursor.moveToFirst();
            }
            return mCursor;
        }

        private ContentValues createContentValues(String name) {
            ContentValues values = new ContentValues();
            values.put(KEY_NAME, name);
            return values;
        }
    }

peoplesetting (where the user enters in new people to add to the database)

package com.b.wom;

import com.b.wom.peopledatabase.peopleDbAdapter;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.Toast;

public class peoplesettings extends Activity {
    public TableRow tr;
    public EditText n;
    public int currentimage;
    public TableLayout tl;
    public Button add;
    public EditText et;
    public SharedPreferences s;
    private peopleDbAdapter database;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.peoplesettings);
        // sets up database
        database = new peopleDbAdapter(this);
        database.open();
        // Adds button for adding more people
        Button add = (Button) findViewById(R.id.add);
        // allocates the namebox
        Button pb = (Button) findViewById(R.id.peoplebutton);
        pb.setBackgroundColor(0x0106000d);
        pb.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                Intent myIntent = new Intent(peoplesettings.this, peopleListView.class);
                startActivity(myIntent);
            }

        });
        n = (EditText) findViewById(R.id.namebox);
        add.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // Adds another person
                add();
            }
        });
    }

    void add() {
        // checks the text in the name box to make sure it isn't empty
        if (n.toString() == "") {
            Toast.makeText(this, "Please enter a name into the text box...",
                    2000).show();
        }
        if (n.toString() != "") {
            database.open();
            database.createPerson(n.getText().toString());
            n.setText("");
            Toast.makeText(this, "Person added...",
                    2000).show();
            database.close();
        }
    }

}

peopleListView(where the app displays all the people in the database)

package com.b.wom;

import com.b.wom.peopledatabase.peopleDbAdapter;

import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class peopleListView extends ListActivity {
    private Cursor cursor;
    private peopleDbAdapter database;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        updatelistview();
    }

    void updatelistview() {
        ListView lv = getListView();
        database.open();
        cursor = database.fetchAllPeople();
        startManagingCursor(cursor);
        String[] from = new String[] { peopleDbAdapter.KEY_NAME };
        int[] to = { R.id.person_name, R.id.person_num };
        // Now create an array adapter and set it to display using our row
        SimpleCursorAdapter people = new SimpleCursorAdapter(this,
                R.layout.person_textview, cursor, from, to);
        lv.setAdapter(people);
        database.close();
    }
}

Logcat data…

    08-24 09:08:59.056: ERROR/Database(872): Error inserting name=BB
08-24 09:08:59.056: ERROR/Database(872): android.database.sqlite.SQLiteException: near "table": syntax error: , while compiling: INSERT INTO table(name) VALUES(?);
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteProgram.native_compile(Native Method)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteProgram.compile(SQLiteProgram.java:110)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:59)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:41)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1027)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1413)
08-24 09:08:59.056: ERROR/Database(872):     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1286)
08-24 09:08:59.056: ERROR/Database(872):     at com.b.wom.peopledatabase.peopleDbAdapter.createPerson(peopleDbAdapter.java:40)
08-24 09:08:59.056: ERROR/Database(872):     at com.b.wom.peoplesettings.add(peoplesettings.java:65)
08-24 09:08:59.056: ERROR/Database(872):     at com.b.wom.peoplesettings$2.onClick(peoplesettings.java:53)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.View.performClick(View.java:2364)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.View.onTouchEvent(View.java:4179)
08-24 09:08:59.056: ERROR/Database(872):     at android.widget.TextView.onTouchEvent(TextView.java:6541)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.View.dispatchTouchEvent(View.java:3709)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-24 09:08:59.056: ERROR/Database(872):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:884)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1659)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1107)
08-24 09:08:59.056: ERROR/Database(872):     at android.app.Activity.dispatchTouchEvent(Activity.java:2061)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1643)
08-24 09:08:59.056: ERROR/Database(872):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1691)
08-24 09:08:59.056: ERROR/Database(872):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-24 09:08:59.056: ERROR/Database(872):     at android.os.Looper.loop(Looper.java:123)
08-24 09:08:59.056: ERROR/Database(872):     at android.app.ActivityThread.main(ActivityThread.java:4363)
08-24 09:08:59.056: ERROR/Database(872):     at java.lang.reflect.Method.invokeNative(Native Method)
08-24 09:08:59.056: ERROR/Database(872):     at java.lang.reflect.Method.invoke(Method.java:521)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
08-24 09:08:59.056: ERROR/Database(872):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
08-24 09:08:59.056: ERROR/Database(872):     at dalvik.system.NativeStart.main(Native Method)

Thanks a ton for whatever you can provide,

Cheers…

  • 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-25T00:18:36+00:00Added an answer on May 25, 2026 at 12:18 am

    The database insertion code is this:
    INSERT INTO table(name) VALUES(?)
    So, you just miss the variable name "TABLE_NAME". You declared your table as todoand use it as table.
    Just put:
    private static final String DATABASE_TABLE = "todo";in peopleDBAdapter.

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

Sidebar

Related Questions

Hello we have an SQL server application running over a low bandwith connection. We
Hello Stack Overflow contributers, I'm a novice programmer learning Python right now, and I
Hello every one. I'm faced with a weird problem. My application has a simple
favorite Hello Everyone, I want retrieve daily latest NAV based on AMFI RSS Feeds
Hello how can we do the note-taking application using natural handwriting in iPad like
Hello I am building an application that is going to execute a block of
Hello all in my iphone application after sending login xml request am getting following
Hello my Japplet is using a JComboBox and 5 JRadioButtons to draw and paint
hello i want to build silverlight application for wince6.0. im not getting whether we
hello im a bit confused here. lets say we are making a simple page

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.