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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T17:25:26+00:00 2026-06-09T17:25:26+00:00

Well this is my DatabaseHelper class public class DatabaseHelper extends SQLiteOpenHelper { static final

  • 0

Well this is my DatabaseHelper class

public class DatabaseHelper extends SQLiteOpenHelper {

    static final String dbName="demoDB";

    public DatabaseHelper(Context context) {
            super(context, dbName, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
            String sql = "CREATE TABLE IF NOT EXISTS players (" +
                                            "id INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                                            "playerName TEXT)";
            db.execSQL(sql);

            ContentValues values = new ContentValues();

            values.put("playerName", "John");
            db.insert("players", "playerName", values);

            values.put("playerName", "George");
            db.insert("players", "playerName", values);

            values.put("firstName", "Marie");
            db.insert("players", "playerName", values);
            System.out.println("Hello");

    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            db.execSQL("DROP TABLE IF EXISTS players");
            onCreate(db);
    }

}

And in my main activity this is what I do to get its data.

if (cursor!= null) {
            if (cursor.moveToFirst()) {
                do {
                     System.out.println(cursor.getString(cursor.getColumnIndexOrThrow("playerName")));            
                } while (cursor.moveToNext());
            }
        }

Why the column is not created?
and I am getting this exception.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/com.mkyong.android.Stats}: java.lang.IllegalArgumentException: column 'playerName' does not exist
  • 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-09T17:25:27+00:00Added an answer on June 9, 2026 at 5:25 pm

    Are you selecting anything before you interact with the cursor? Your cursor should be the result from a “Select…” SQL call, but I don’t see one in your DatabaseHelper or anything in your MainActivity to indicate you are doing any sort of selection.

    Also, when you are inserting values into your table , I believe the second parameter should be null [db.insert("players", null, values)]. It’s intended for the nullColumnHack, which you use if you aren’t entering any data into row.

    nullColumnHack  optional; may be null. SQL doesn't allow inserting a completely empty row without naming at least one column name. If your provided values is empty, no column names are known and an empty row can't be inserted. If not set to null, the nullColumnHack parameter provides the name of nullable column name to explicitly insert a NULL into in the case where your values is empty. 
    

    Edit

    Well, so far you’ve created a table and inserted some records. The next step would be to create basic CRUD operations (Create, Retrieve, Update, Delete), but for your case, you need to start with Retrieve.

    Retrieve basically means you are reading/retrieving data from your database, so you can use it in your application. When you read the data from a DB, it gets stored in a Cursor. So, you need to:

    1. Create a method in your database helper to read data from your database
    2. From your main activity, call the method you created in step #1. Result is stored in a cursor.
    3. In your main method, extract the data from the Cursor so you can use it. (Looks like you’ve already attempted this in your main activity).

    Here is a link to a great tutorial on setting up a databse and how to create CRUD operations for your database. For now, scroll down and read up on the Retrieve operation.
    http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/

    I would read the entire tutorial if I were you. There are lots of other helpful tips and suggestions that will be well worth the investment now. For example, creating constants in your DatabaseHelper class for the table name, database name, column name is a really good idea because sooner or later you’re going to make a typo if you keep typing in all the column and table names manually. If you use variables, you’ll get a compile error rather than an exception at runtime.

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

Sidebar

Related Questions

I have a class extends NamedParameterJdbcDaoSupport. well this superclass has a final setDataSource method
I don't understand very well this code: var img = $('<img/>', {class: photo, src:
Well this JSON I have doesn't work on PHP Json_decode, it returns NULL, and
Well this is the html code: <? $html ='<table cellspacing=0 cellpadding=0 class=mytable> <tr> <th
Well this interactive python console snippet will tell everything: >>> class Test: ... def
Well this is weird let me describe the scenario I have this mailer define
Well this file was put in the repo by mistake and was deleted and
Well this is a really weird issue, I really didn't find anything on this
well this is my problem i use 2 source first query (select * from
Well this is a simple question i want to filter two elements sorted reverse

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.