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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:48:29+00:00 2026-06-15T05:48:29+00:00

I am trying to insert into the SQLite Database but it keeps on force

  • 0

I am trying to insert into the SQLite Database but it keeps on force closing every time I run my program on the emulator. I think it has something to due with my syntax of my database creation but I have triple checked it and can’t find my error. The only other thing I can think of is if I have to add something to the manifest to properly run a SQlite database.

Below is my code for my helper class.

public class dbhelper extends SQLiteOpenHelper {

    public static final String DATABASE_NAME = "swimmers";
    public static final String TABLE_SWIMMERS = "sfd table";

    public static final String C_ID = "id";
    public static final String NAME = "name";
    public static final String TEAM = "team";
    public static final String NOTES = "notes";

    public static final int VERSION = 1;

    public dbhelper(Context context)
    {
        super(context, DATABASE_NAME, null, VERSION);
    }

    @Override
    public void onCreate (SQLiteDatabase db) 
    {
        String createdb = "create table " + TABLE_SWIMMERS + "(" + C_ID + " integer primary key autoincrement, " + NAME + " text, " + TEAM + " text, " + NOTES + " text); ";
        db.execSQL(createdb);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    {
        db.execSQL("drop table " + TABLE_SWIMMERS);
        onCreate(db);
    }

    //add new entry
    void addSwimmer(Swimmer swimmer){

        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(NAME, swimmer.getname());
        values.put(TEAM, swimmer.getteam());
        values.put(NOTES, swimmer.getnotes());

        db.insert(TABLE_SWIMMERS, null, values);
        db.close();
    }

    //Getting single swimmer
    Swimmer getSwimmer(int id){
        SQLiteDatabase db = this.getReadableDatabase();

        Cursor cursor = db.query(TABLE_SWIMMERS, new String[] { C_ID, NAME, TEAM, NOTES}, C_ID + "=?", new String[] { String.valueOf(id) }, null, null, null, null);
        if (cursor !=null)
            cursor.moveToFirst();

        Swimmer swimmer = new Swimmer (Integer.parseInt(cursor.getString(0)), cursor.getString(1), cursor.getString(2), null);
        return swimmer;
    }

    public int updateSwimmer(Swimmer swimmer){
        SQLiteDatabase db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        values.put(NAME, swimmer.getname());
        values.put(TEAM, swimmer.getteam());
        values.put(NOTES, swimmer.getnotes());

        return db.update(TABLE_SWIMMERS, values, C_ID + " = ?", new String[] { String.valueOf(swimmer.getID()) });        
    }

    //delete single contact
    public void deleteSwimmer(Swimmer swimmer){
        SQLiteDatabase db = this.getWritableDatabase();
        db.delete(TABLE_SWIMMERS, C_ID + " = ?", new String[] { String.valueOf(swimmer.getID()) });        
        db.close();
    }

    //get contacts count
    public int getSwimmersCount(){
        String countQuery = "SELECT  * FROM " + TABLE_SWIMMERS;
        SQLiteDatabase db = this.getReadableDatabase();
        Cursor cursor = db.rawQuery(countQuery, null);
        cursor.close();
        return cursor.getCount();
    }

}

Below is my Swimmer class that I made and I am trying to insert a Swimmer into the database.

public class Swimmer {

//private variables
int _id;
String _name;
String _team;
String _notes;


public Swimmer(int id, String name, String team, String notes){
    this._id = id;
    this._name = name;
    this._team = team;
    this._notes = notes;
}

public Swimmer(String name, String team, String notes){
    this._name = name;
    this._team = team;
    this._notes = notes;
}

public int getID(){
    return this._id;
}

public void setID(int id){
    this._id = id;
}

public String getname(){
    return this._name;
}

public void setname(String name){
    this._name = name;
}

public String getteam(){
    return this._team;
}

public void setteam(String team){
    this._team = team;
}

public String getnotes(){
    return this._notes;
}

public void setnotes(String notes){
    this._notes = notes;
}
}

Here is my code to open and insert into the database.

public class CreateNewSwimmerProfile extends Activity {

private dbhelper db;

private final String TAG = "Create New Profile";

@Override
public boolean onCreateOptionsMenu(Menu menu) 
{       
        getMenuInflater().inflate(R.menu.activity_sfdmain, menu);
        return true;
    }

@Override

public void onCreate (Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    Log.i("createProfileActivity", "Intent Text");

    setContentView(R.layout.createprofile);
    Intent createprofileintent = getIntent();
    db = new dbhelper(this);
}

public void btn_CLICK_addswimmer (View w)
{   
    Log.i("Insert: ", "Inserting ..");      

    String name,team,notes;

    EditText nameIn = (EditText) findViewById(R.id.editText_name);
    EditText teamIn = (EditText) findViewById(R.id.editText_team);
    EditText notesIn = (EditText) findViewById(R.id.editText_notes);

    name = nameIn.getText().toString();
    team = teamIn.getText().toString();
    notes = notesIn.getText().toString();

    Swimmer test = new Swimmer(name, team, notes);
    db.addSwimmer(test);
}

public void btn_CLICK_cancel (View b)
{
        Log.i(TAG, "start create new profile activity");
        Intent intent = new Intent(this, SFDMain.class);
        startActivity(intent);
}

}

And here are my errors when I try to insert the swimmer.

11-27 08:58:36.150: E/AndroidRuntime(643): FATAL EXCEPTION: main
11-27 08:58:36.150: E/AndroidRuntime(643): java.lang.IllegalStateException: Could not     execute method of the activity
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.view.View$1.onClick(View.java:3591)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.view.View.performClick(View.java:4084)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.view.View$PerformClick.run(View.java:16966)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.os.Handler.handleCallback(Handler.java:615)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.os.Handler.dispatchMessage(Handler.java:92)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.os.Looper.loop(Looper.java:137)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.app.ActivityThread.main(ActivityThread.java:4745)
11-27 08:58:36.150: E/AndroidRuntime(643):  at                                                                         java.lang.reflect.Method.invokeNative(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643):  at java.lang.reflect.Method.invoke(Method.java:511)
11-27 08:58:36.150: E/AndroidRuntime(643):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
11-27 08:58:36.150: E/AndroidRuntime(643):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
11-27 08:58:36.150: E/AndroidRuntime(643):  at dalvik.system.NativeStart.main(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643): Caused by: java.lang.reflect.InvocationTargetException
11-27 08:58:36.150: E/AndroidRuntime(643):  at java.lang.reflect.Method.invokeNative(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643):  at java.lang.reflect.Method.invoke(Method.java:511)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.view.View$1.onClick(View.java:3586)
11-27 08:58:36.150: E/AndroidRuntime(643):  ... 11 more
11-27 08:58:36.150: E/AndroidRuntime(643): Caused by: android.database.sqlite.SQLiteException: near "table": syntax error (code 1): , while compiling: create table sfd table(id integer primary key autoincrement, name text, team text, notes text);
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
11-27 08:58:36.150: E/AndroidRuntime(643):  at com.sfd.swimming.feedback.display.system.dbhelper.onCreate(dbhelper.java:35)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
11-27 08:58:36.150: E/AndroidRuntime(643):  at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
11-27 08:58:36.150: E/AndroidRuntime(643):  at com.sfd.swimming.feedback.display.system.dbhelper.addSwimmer(dbhelper.java:48)
11-27 08:58:36.150: E/AndroidRuntime(643):  at com.sfd.swimming.feedback.display.system.CreateNewSwimmerProfile.btn_CLICK_addswimmer(CreateNewSwimmerProfile.java:50)
11-27 08:58:36.150: E/AndroidRuntime(643):  ... 14 more
11-27 08:58:36.420: D/dalvikvm(643): GC_CONCURRENT freed 207K, 4% free 8241K/8519K, paused 22ms+33ms, total 304ms
11-27 08:58:38.680: I/Process(643): Sending signal. PID: 643 SIG: 9

ANY help is greatly appreciated!!

  • 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-15T05:48:30+00:00Added an answer on June 15, 2026 at 5:48 am

    table is a Keyword for SQLite. Try to change your variable TABLE_SWIMMERS from TABLE_SWIMMERS = "sfd table"; to TABLE_SWIMMERS = "sfd"; and it will work.

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

Sidebar

Related Questions

I'm trying to insert data into the SQLite database using get EditText, but I
I'm trying to insert text into my SQLite database, but for some reason it
I'm trying to insert some data into my SQLite database. But I keeo receiving
I am working on sqlite database , trying to insert into database but it
I'm trying to insert values into my sqlite database in iphone application, but with
I'm trying to insert data into a database when there is no network, but
I'm trying to insert non-latin data into sqlite database using bind variables using System.Data.SQLite.
I am trying to insert a datetime value into a SQLite database. It seems
Hello I'm trying to save string into SQLite database, but nothing happens. I have
How to insert data into table in sqlite iPhone? I am trying following, but

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.