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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:17:25+00:00 2026-06-12T05:17:25+00:00

I copied an example of sqlite use from somewhere. They defined 5 columns and

  • 0

I copied an example of sqlite use from somewhere. They defined 5 columns and I change it to 4 columns.
The relevant part is here:

    private final String DB_NAME = "mcustomerDbName";
    private final String TABLE_NAME = "mcustomeTableName";
    SQLiteDatabase customersDB = null;
    /** Called when the activity is first created. */


     ..........................................

This is the context of the table-4 columns

    private void mFillDbsTable(){
        try {

            customersDB.execSQL("INSERT INTO " +
                    TABLE_NAME + 
                    " Values ('ABARTH','500','Abarth','15.3846153846154' );");
            customersDB.execSQL("INSERT INTO " + TABLE_NAME + "Values ( 'ABARTH ', 'Grande Punto ', '1.4 T-Jet 155 ', '14.9253731343284 ' );");
            customersDB.execSQL("INSERT INTO " + TABLE_NAME + "Values ( 'ALFA ROMEO ', 'MiTo ', '1.4 16v TB 120  ', '16.3934426229508 ');");
            customersDB.execSQL("INSERT INTO " + TABLE_NAME + "Values ( 'ALFA ROMEO ', 'MiTo ', '1.3 JTDm 90 ', '22.2222222222222 ');");
            customersDB.execSQL("INSERT INTO " + TABLE_NAME + "Values ( 'ALFA ROMEO ', '147 ', '1.6 (120 bhp) ', '12.1951219512195 ');");
            customersDB.execSQL("INSERT INTO " + TABLE_NAME + "Values ( 'ALFA ROMEO ', '147 ', '2.0 ', '11.2359550561798 ');");

     ..........................................

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    /*setContentView(R.layout.activity_delek);**/
     ArrayList<String> results = new ArrayList<String>();
        try {
            customersDB =  this.openOrCreateDatabase(  DB_NAME, MODE_PRIVATE, null);
            customersDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                    TABLE_NAME +
                    " (Name VARCHAR," +
                    " Street VARCHAR, Block VARCHAR, City VARCHAR);");
            mFillDbsTable();
             Cursor c = customersDB.rawQuery("SELECT Name, Street, Block, City  FROM "    +
                    TABLE_NAME +
                       " where Name == 'TOYOTA' or Name == 'Yosi' ", null);
            if (c != null ) {
                if  (c.moveToFirst()) {
                    do {
                        String name = c.getString(c.getColumnIndex("Name"));
                           String street = c.getString(c.getColumnIndex("Street"));

                              String city = c.getString(c.getColumnIndex("City"));

                            results.add(name + ", " + street + " "+ city );
                    }while (c.moveToNext());
                }
            }
            setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
         } catch (SQLiteException se ) {
            Log.e(getClass().getSimpleName(), "create/Open the database problem");
        } finally {
            if (customersDB != null)
                customersDB.execSQL("DELETE FROM " +   TABLE_NAME);
                customersDB.close();
        }

I get this message in the log:

 10-01 21:59:59.434: I/Database(1067): sqlite returned: error code = 1, msg = table            mcustomeTableName has 5 columns but 4 values were supplied.

Why??I have 4 columns

  • 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-12T05:17:26+00:00Added an answer on June 12, 2026 at 5:17 am

    The table probably already existed from a previous run without your changes and still has 5 columns in the database (CREATE TABLE IF NOT EXISTS). You can verify this by logging on to sqllite from ADP. Just drop the table before you run your app.

    In addition, provide a column list with your insert statements. This is good practice regardless, because your applicaton will be more robust towards schema changes:

    "INSERT INTO " + TABLE_NAME + " (Name, Street, Block, City) Values (" ...etc
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I copied an example project from here , but I don't understand part of
From here I've copied an example of python gui app, but it's not working.
I copied the following example from an SQLite Java library website: PreparedStatement prep =
I am learning to use mahout by starting with a example copied from the
I copied this example from api.jquery.com $('.target').change(function() { alert('Handler for .change() called.'); }); I
I copied everything from the Google marker clusterer example here and just changed the
I copied the example straight from their page: http://jsfiddle.net/D2RLR/631/ ... and I get the
I ran an example copied from: http://developers.facebook.com/docs/reference/javascript/ http://developers.facebook.com/docs/reference/javascript/FB.api/ (I only changed my APP_ID) <div
I copied this code from an example . I've read it 100 times. Array.prototype.map
I've copied and pasted the example ejb-jar.xml and jboss.xml file from http://docs.jboss.org/jbossas/jboss4guide/r4/html/ch6.chapt.html#ch6.mdbejbjar.ex and I'm

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.