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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:33:20+00:00 2026-06-08T15:33:20+00:00

Can find why i get this error can someone help? package Android.data; public class

  • 0

Can find why i get this error can someone help?

package Android.data;

public class CarsDbConstants 
{

public static final String DATABASE_NAME = "cars.db";

public static final int DATABASE_VERSION = 1;
public static final String CARS_TABLE_NAME = "cars";

public static final String CAR_ID = "_id";
public static final String CAR_MANUFACTURER = "manufacturer";
public static final String CAR_YEAR= "year";
public static final String LOG_TAG = "CarsDb";

}

package Android.data;

public class CarsDBHelper extends SQLiteOpenHelper 
{
 public CarsDBHelper(Context context, String name, CursorFactory factory,
        int version)
{
    super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) 
{
    Log.d(LOG_TAG, "Creating all the tables");

    String CREATE_CARS_TABLE = 
            "CREATE TABLE " + CARS_TABLE_NAME + 
       "("  + CAR_ID + " INTEGER PRIMARY KEY,"
            + CAR_MANUFACTURER + " TEXT,"
            + CAR_YEAR + " INTEGER"+")";
    try 
    {
        db.execSQL(CREATE_CARS_TABLE);
    }
    catch (SQLiteException ex)
    {
        Log.e(LOG_TAG, "Create table exception: " + ex.getMessage());
    }
}
  }

   public void addCar(Cars car)
    {
        db = dbhelper.getWritableDatabase();

        ContentValues newCarValues = new ContentValues();
        //newCarValues.put(CAR_ID,car.get_id());
        newCarValues.put(CAR_MANUFACTURER, car.getManufacturer());
        newCarValues.put(CAR_YEAR, car.getYear());


        // Inserting the new row, or throwing an exception if an error occurred
        try
        {
            db.insertOrThrow(CARS_TABLE_NAME, null, newCarValues);
        }
        catch (SQLiteException ex)
        {
            Log.e(LOG_TAG, ex.getMessage());
            throw ex;
        }   
        finally
        {
            db.close();
        }
    }

     package Android.hwsqldb;

     public class MainActivity extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    CarsHandler db = new CarsHandler(this);
    insertCars(db);
    Cursor cursor = db.getAllCars();
    this.startManagingCursor(cursor);
    showCars(cursor);
}



private void showCars(Cursor c) {
    Log.d("Reading:", "Reading all cars");

    ArrayList<String> items = new ArrayList<String>();

    while (c.moveToNext()) {
        items.add(String.format("%s: %s\n\t%s, %s",
                c.getInt(c.getColumnIndex(CAR_ID)),
                c.getString(c.getColumnIndex(CAR_MANUFACTURER)),
                c.getInt(c.getColumnIndex(CAR_YEAR))));
    }

    ListView lv = (ListView) findViewById(R.id.listView1);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, items);
    lv.setAdapter(adapter);
}





private void insertCars(CarsHandler db) 
{
    Log.d("Inserting:", "Inserting cars to DB");

    db.addCar(new Cars(1,"Subaru", 1987));
    db.addCar(new Cars(2,"Fiat", 1921));
    db.addCar(new Cars(3,"Susita", 1956));
    db.addCar(new Cars(4,"Mesrsedes", 1923));   
}

Error Thrown:

07-29 07:08:47.315: E/AndroidRuntime(1165): FATAL EXCEPTION: main

07-29 07:08:47.315: E/AndroidRuntime(1165): java.lang.RuntimeException: Unable to start activity ComponentInfo{Android.hwsqldb/Android.hwsqldb.MainActivity}: java.util.MissingFormatArgumentException: Format specifier: s

DB table created contains all data.

  • 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-08T15:33:22+00:00Added an answer on June 8, 2026 at 3:33 pm

    public static final String CAR_YEAR= “year”;

    You can change the column name like

    public static final String CAR_YEAR= “_year”;

    then test your code and check database and table is created or not from android DDMS file Explorer.

    your code block ::

    @Override
    public void onCreate(Cdb)
    {
    Log.d(LOG_TAG, “Creating all the tables”);

    what is this parameter ‘SQLiteDatabase db’ . It is accepted to pass SQLiteDatabase parameter into onCreate() method.

    You can call SQLiteDatabase class.

    SQLiteDatabase db = new SQLiteDatabase () into onCreate() method

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

Sidebar

Related Questions

I get this error a LOT, and i never know why. Can someone help
I can't find any solution to get this jquery events to work. $(window).one('click',function(){ console.log('hide
Hi i got stuck with this problem, i can't find out how to get
I simply can not get Visual Studio 2005 to find the System.Configuration.ConfigurationManager class. Here
Can someone help me explain what is happening here? Sorry if this is a
I can't find an answer to this question anywhere so I'm hoping someone can
can someone help me spot the problem here ? #!/bin/sh find . -name '*ABC*'
I was wondering how I can't get rid of this error. I have a
I would like to get contents of some stream or project I can find
I can't find a correct way to get the environment variable for the appdata

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.