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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:53:32+00:00 2026-06-17T09:53:32+00:00

This is actually the first time that i try to use a SQL database

  • 0

This is actually the first time that i try to use a SQL database on android. So i hope you can help me with it.
I am current working on a leadbord in our game and wanted to write the Communicationclass for it but i got in troubles with it. i used http://www.vogella.com/articles/AndroidSQLite/article.html for it. and this is how my Db Helper class looks like

public class MySQLiteHelper extends SQLiteOpenHelper {

public static final String TABLE_LEADBOARD = "leadboard";
public static final String COLUMN_ID = "_id";
public static final String COLUMN_NAME = "name";
public static final String COLUMN_LEVEL = "level";
public static final String COLUMN_KILLPOINTS = "killpoints";

private static final String DATABASE_NAME = "leadboard.db";
private static final int DATABASE_VERSION = 1;

// Database creation sql statement
private static final String DATABASE_CREATE = "create table "
    + TABLE_LEADBOARD + "(" + COLUMN_ID
    + " integer primary key autoincrement, " + COLUMN_NAME
    + " text,"+ COLUMN_LEVEL + " integer," +COLUMN_KILLPOINTS + " integer);";

public MySQLiteHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

@Override
public void onCreate(SQLiteDatabase database) {
    database.execSQL(DATABASE_CREATE);
}

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

i wrote a simple element that has the 4 Fields and getter and setter

public class LeadbordElement {
    private long id;
    private int level;
    private int killPoints;
    private String name;

my connection class looks like this now

public class DatabaseCommunication {
    // Database fields
    private SQLiteDatabase database;
    private MySQLiteHelper dbHelper;
    // all columns for the query
    private String[] allColumns = { MySQLiteHelper.COLUMN_ID,
            MySQLiteHelper.COLUMN_NAME, MySQLiteHelper.COLUMN_LEVEL,
            MySQLiteHelper.COLUMN_KILLPOINTS };

    public DatabaseCommunication(Context context) {
        dbHelper = new MySQLiteHelper(context);
    }

    public void open() throws SQLException {
        database = dbHelper.getWritableDatabase();
    }

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

    /**
     * Save element to database
     * 
     * @author Benjamin M. 17.01.2013
     * @param element
     */
    public void addLeadbordElement(LeadbordElement element) {
        this.open();
        ContentValues values = new ContentValues();
        values.put(MySQLiteHelper.COLUMN_NAME, element.getName());
        values.put(MySQLiteHelper.COLUMN_LEVEL, element.getLevel());
        values.put(MySQLiteHelper.COLUMN_KILLPOINTS, element.getKillPoints());
        database.insert(MySQLiteHelper.TABLE_LEADBOARD, null, values);
        this.close();
    }

    /**
     * Methode to get a Vektor of elements
     * 
     * @author Benjamin M. 17.01.2013
     */
    public Vector<LeadbordElement> getTop10() {
        this.open();
        // should return ordert by killpoints
        Cursor cursor = database.query(MySQLiteHelper.TABLE_LEADBOARD,
                allColumns, null, null, null, null,
                MySQLiteHelper.COLUMN_KILLPOINTS + " DESC");

        Vector<LeadbordElement> elements = new Vector<LeadbordElement>();

        //creating the vector of elements
        cursor.moveToFirst();
        while (!cursor.isAfterLast()) {
            elements.add(this.createElement(cursor));
            cursor.moveToNext();
        }
        cursor.close();
        this.close();
        return elements;
    }

    /**
     * Methode to create a LeadbordElement out of the cursor
     * 
     * @author Benjamin M. 17.01.2013
     * @param cursor
     * @return
     */
    private LeadbordElement createElement(Cursor cursor) {
        LeadbordElement element = new LeadbordElement();
        element.setId(cursor.getLong(0));
        element.setName(cursor.getString(1));
        element.setLevel(cursor.getInt(2));
        element.setKillPoints(cursor.getInt(3));
        return element;
    }
}

But this acutally does not work. I cant get the top10 of it like this, and i dont get the misstake of it. Well actually i can create the DatabaseCommunication and i can add an element. not sure if it really get added to a database. But i cant get those back.
It says there is no Column: level: , while compiling: select _id …….

At least i got a textview and want to display the elements there.

Thanks if you can help!

Errorlog:

01-17 19:04:35.920: E/AndroidRuntime(1428): FATAL EXCEPTION: main
01-17 19:04:35.920: E/AndroidRuntime(1428): java.lang.IllegalStateException: Could not execute method of the activity
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.view.View$1.onClick(View.java:3044)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.view.View.performClick(View.java:3511)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.view.View$PerformClick.run(View.java:14110)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.os.Handler.handleCallback(Handler.java:605)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.os.Looper.loop(Looper.java:137)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.app.ActivityThread.main(ActivityThread.java:4424)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at java.lang.reflect.Method.invoke(Method.java:511)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at dalvik.system.NativeStart.main(Native Method)
01-17 19:04:35.920: E/AndroidRuntime(1428): Caused by: java.lang.reflect.InvocationTargetException
01-17 19:04:35.920: E/AndroidRuntime(1428):     at java.lang.reflect.Method.invokeNative(Native Method)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at java.lang.reflect.Method.invoke(Method.java:511)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.view.View$1.onClick(View.java:3039)
01-17 19:04:35.920: E/AndroidRuntime(1428):     ... 11 more
01-17 19:04:35.920: E/AndroidRuntime(1428): Caused by: android.database.sqlite.SQLiteException: no such column: level: , while compiling: SELECT _id, name, level, killpoints FROM leadboard ORDER BY killpoints DESC
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1564)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1449)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1405)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1485)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at control.database.DatabaseCommunication.getTop10(DatabaseCommunication.java:61)
01-17 19:04:35.920: E/AndroidRuntime(1428):     at com.main.MainActivity.startLeadbord(MainActivity.java:178)
01-17 19:04:35.920: E/AndroidRuntime(1428):     ... 14 more
  • 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-17T09:53:33+00:00Added an answer on June 17, 2026 at 9:53 am

    i think i see it…pls add a (missing) whitespace after COLUMN_LEVEL and COLUMN_KILLPOINTS

    from…

    private static final String DATABASE_CREATE = "create table "
        + TABLE_LEADBOARD + "(" + COLUMN_ID
        + " integer primary key autoincrement, " + COLUMN_NAME
        + " text,"+ COLUMN_LEVEL + "integer," +COLUMN_KILLPOINTS + "integer);";
    

    to….

    private static final String DATABASE_CREATE = "create table "
        + TABLE_LEADBOARD + "(" + COLUMN_ID
        + " integer primary key autoincrement, " + COLUMN_NAME
        + " text,"+ COLUMN_LEVEL + " integer," +COLUMN_KILLPOINTS + " integer);";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm very new to trigger function. Actually this is the first time I'm using
The first part of this question is actually a request for confirmation based on
I am actually stuck in merging the result of this two queries: first query:
If I use INT(12) vs INT(10) or INT(8) what will this actually do in
I understand that 2 options are available: Non-persistent Persistent But what does this actually
First time asking a question here. Usually I can find my answer without having
I am trying to use a closure to ensure that a function can only
please help on this issue: Within a loop, I first call a function, which
First i'll just state that I'm using singletons that won't actually be around throughout
I have two questions, actaully... First off, Why cant I do this: List<Object> object

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.