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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:11:38+00:00 2026-05-26T17:11:38+00:00

I am new to android platform. I am working on a project in which

  • 0

I am new to android platform. I am working on a project in which I have to make a shared calender with two calendar interfaces on one activity. User can save an event with event details that is event title, event time, remainder, description, to and from etc. I have done notepad tutorial given on android website. I made my application on same pattern. But I am unable to locate error. Every time I run my code SQLite Exception with error code 1 hits. I have spent more than 20 hours on it but could not find any solution. I have tried to debug it too but no use at all. Kindly help me solving this error. It would be a great help. Thank you all in advance.

this where m trying to insert into the database

import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

    public class MyListView extends ListActivity {

        int j=0;
        private EventsDbAdapter mDbHelper;
        private Cursor EventsCursor;

        static final String[] hours = new String[]{
            "00:00",
            "01:00",
            "02:00",
            "03:00",
            "04:00",
            "05:00",
            "06:00",
            "07:00",
            "08:00",
            "09:00",
            "10:00",
            "11:00",
            "12:00",
            "13:00",
            "14:00",
            "15:00",
            "16:00",
            "17:00",
            "18:00",
            "19:00",
            "20:00",
            "21:00",
            "22:00",
            "23:00"
        };
        private int pos=0;
        private int ACTIVITY_CREATE=0;
        private ArrayAdapter<String> ar;
        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);

            ar = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, hours);
            setListAdapter(ar);
            getListView().setTextFilterEnabled(true);

            mDbHelper = new EventsDbAdapter(this);
            mDbHelper.open();

        }

        protected void onListItemClick(ListView l, View v, int position, long id) {
            super.onListItemClick(l, v, position, id);
            pos = position;

            String str = this.getListAdapter().getItem(position).toString();

            if(str.length()<6)
            {
                Intent myIntent = new Intent(MyListView.this, event.class);
                MyListView.this.startActivityForResult(myIntent,0);
            }
            else
            {
                Cursor c = EventsCursor;
                EventsCursor=mDbHelper.fetchAllNotes();
                startManagingCursor(EventsCursor);

                // Create an array to specify the fields we want to display in the list (only TITLE)
                String[] from = new String[]{EventsDbAdapter.KEY_TITLE};


                c.moveToPosition(position);

                Intent i = new Intent(this, event.class);

                i.putExtra(EventsDbAdapter.KEY_ROWID, id);

                i.putExtra(EventsDbAdapter.KEY_TITLE, c.getString(c.getColumnIndexOrThrow(EventsDbAdapter.KEY_TITLE)));

                i.putExtra(EventsDbAdapter.KEY_TO, c.getString(c.getColumnIndexOrThrow(EventsDbAdapter.KEY_TO)));

                i.putExtra(EventsDbAdapter.KEY_FROM, c.getString(c.getColumnIndexOrThrow(EventsDbAdapter.KEY_FROM)));

                i.putExtra(EventsDbAdapter.KEY_DESCRIPTION, c.getString(c.getColumnIndexOrThrow(EventsDbAdapter.KEY_DESCRIPTION)));

                startActivityForResult(i, 1);
            }
     }



        @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
               super.onActivityResult(requestCode, resultCode, intent);

               Bundle extras = intent.getExtras();

                if(requestCode==0 && resultCode==-1)
                {
                        String title = extras.getString(EventsDbAdapter.KEY_TITLE);
                        String to = extras.getString(EventsDbAdapter.KEY_TO);
                        String from = extras.getString(EventsDbAdapter.KEY_FROM);
                        String description = extras.getString(EventsDbAdapter.KEY_DESCRIPTION);
                        mDbHelper.createEvent(title, to,from,description);
                        hours[pos]=hours[pos]+title;
                        ar.notifyDataSetChanged();

                }
                else if(requestCode==1)
                {
                    Long rowId = extras.getLong(EventsDbAdapter.KEY_ROWID);
                    if (rowId != null) {
                        String editTitle = extras.getString(EventsDbAdapter.KEY_TITLE);
                        String to = extras.getString(EventsDbAdapter.KEY_TO);
                        String from = extras.getString(EventsDbAdapter.KEY_FROM);
                        String description = extras.getString(EventsDbAdapter.KEY_DESCRIPTION);
                        mDbHelper.updateEvent(rowId, editTitle, to,from,description);

                        hours[pos]=hours[pos]+editTitle;
                        ar.notifyDataSetChanged();

                    }
                }
            }
    }

`

public class EventsDbAdapter 
{
    public static final String KEY_TITLE = "title";
    public static final String KEY_TO = "tochecking";
    public static final String KEY_FROM = "fromchecking";
    public static final String KEY_DESCRIPTION = "description";
        public static final String KEY_ROWID = "_id";

        private static final String TAG = "EventsDbAdapter";
        private DatabaseHelper mDbHelper;
        private SQLiteDatabase mDb;

/**
 * Database creation sql statement
 */
    private static final String DATABASE_CREATE =
            " create table " + " DATABASE_TABLE " + " ("
            + KEY_ROWID + " integer primary key autoincrement,      "
            + KEY_TITLE + " text not null, "
            + KEY_TO + " text not null, "
            + KEY_FROM + " text not null,"+KEY_DESCRIPTION+" text not null);";


       private static final String DATABASE_NAME = "data";
       private static final String DATABASE_TABLE = "events";
       private static final int DATABASE_VERSION = 2;

       private final Context mCtx;

       private static class DatabaseHelper extends SQLiteOpenHelper {

       DatabaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
       }
       @Override
       public void onCreate(SQLiteDatabase db) {

        System.out.print("testing");
        db.execSQL(DATABASE_CREATE);
       }

       @Override
       public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
           Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                   + newVersion + ", which will destroy all old data");
           db.execSQL("DROP TABLE IF EXISTS notes");
           onCreate(db);
       }
    }

    /**
     * Constructor - takes the context to allow the database to be
     * opened/created
     * 
     * @param ctx the Context within which to work
     */
      public EventsDbAdapter(Context ctx) {
        this.mCtx = ctx;
      }

    /**
     * Open the notes database. If it cannot be opened, try to create a new
     * instance of the database. If it cannot be created, throw an exception to
     * signal the failure
     * 
     * @return this (self reference, allowing this to be chained in an
     *         initialization call)
     * @throws SQLException if the database could be neither opened or created
     */
    public EventsDbAdapter open() throws SQLException {
        mDbHelper = new DatabaseHelper(mCtx);
        mDb =mDbHelper.getWritableDatabase();
        return this;
    }

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


    /**
     * Create a new note using the title and body provided. If the note is
     * successfully created return the new rowId for that note, otherwise return
     * a -1 to indicate failure.
     * 
     * @param title the title of the note
     * @param body the body of the note
     * @return rowId or -1 if failed
     */
    public long createEvent(String title, String to , String from , String description) {
        ContentValues initialValues = new ContentValues();
        initialValues.put(KEY_TITLE, title);
        initialValues.put(KEY_TO, to);
        initialValues.put(KEY_FROM, from);
        initialValues.put(KEY_DESCRIPTION, description);

        return mDb.insert(DATABASE_TABLE, null, initialValues);


    }

    /**
     * Delete the note with the given rowId
     * 
     * @param rowId id of note to delete
     * @return true if deleted, false otherwise
     */
    public boolean deleteNote(long rowId) {

        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }

    /**
     * Return a Cursor over the list of all notes in the database
     * 
     * @return Cursor over all notes
     */
    public Cursor fetchAllNotes() {

        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,KEY_TO,KEY_FROM,
                KEY_DESCRIPTION}, null, null, null, null, null);
    }

    /**
     * Return a Cursor positioned at the note that matches the given rowId
     * 
     * @param rowId id of note to retrieve
     * @return Cursor positioned to matching note, if found
     * @throws SQLException if note could not be found/retrieved
     */
    public Cursor fetchEvent(long rowId) throws SQLException {

        Cursor mCursor =

            mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID, KEY_TITLE,KEY_TO,KEY_FROM,
                    KEY_DESCRIPTION}, KEY_ROWID + "=" + rowId, null,
                    null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }

    /**
     * Update the note using the details provided. The note to be updated is
     * specified using the rowId, and it is altered to use the title and body
     * values passed in
     * 
     * @param rowId id of note to update
     * @param title value to set note title to
     * @param body value to set note body to
     * @return true if the note was successfully updated, false otherwise
     */
    public boolean updateEvent(long rowId, String title, String to ,String from,String description) {
        ContentValues args = new ContentValues();
        args.put(KEY_TITLE, title);
        args.put(KEY_TO, to);
        args.put(KEY_FROM, from);
        args.put(KEY_DESCRIPTION, description);

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

`

  • 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-26T17:11:38+00:00Added an answer on May 26, 2026 at 5:11 pm

    Is this the problem line?

    " create table " + " DATABASE_TABLE " + " ("
    

    Here, DATABASE_TABLE is a string i.e. you issue CREATE TABLE DATABASE_TABLE

    Later you refer to DATABASE_TABLE the variable i.e. “events”

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

Sidebar

Related Questions

I am new to the android platform. Now I am working on TTS(Text to
When creating a new android project, the build target has two choices: Android 2.2,
Hi i'm new android. i'm working through the samples and have an error when
I'm not new to Java but new to the Android platform. I'm finding one
I am working in android SDK(Eclipse) platform 2.2 and I have been running through
I fairly new to programming for the Android platform and have some question about
I am absolutely new to the Android platform and have been building an application
I am completely new to android, and pretty much a Java newb. I have
I'm pretty new to Android dev and still working out a lot of things.
i'm new at Android world, and i have a doubt, is there any method

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.