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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:44:26+00:00 2026-06-16T13:44:26+00:00

I have been working with AndEngine and developing a game. I have now moved

  • 0

I have been working with AndEngine and developing a game. I have now moved on to trying to implement the scores locking the levels etc. I have been trying to get this sqlite database going for a few hours to really no avail. If I try a level 1 through three it throws errors but still works fine but when I implement a fourth or fifth I cannot access those entries and it force closes. The exact errors I am getting is cursor out of bounds exception and close() was never explicitly called. Any help is appreciated.

Here is my database class

package com.example.test;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

 public class myDatabase extends SQLiteOpenHelper {

    static final String dbName = "myDB";
    static final String tLevels = "Levels";
    static final String fLevelID = "levelNum";
    static final String fLevelUnLocked = "levelLocked";
    static final String fLevelBeat = "levelBeat";
    static final String fLevelScore = "levelScore";

    public myDatabase(Context context) {

            super(context, dbName, null, 1);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {

            db.execSQL("CREATE TABLE IF NOT EXISTS "+tLevels+" (" +
                                    fLevelID + " INTEGER PRIMARY KEY , " +
                                    fLevelUnLocked + " TEXT, " +
                                    fLevelBeat + " TEXT, " +
                                    fLevelScore + " TEXT" +
                                    ")");


             ContentValues cv = new ContentValues();
                    cv.put(fLevelID, 1);
                    cv.put(fLevelUnLocked, "true");
                    cv.put(fLevelBeat, "false");
                    cv.put(fLevelScore, "0");
                            db.insert(tLevels, null, cv);
                    cv.put(fLevelID, 2);
                    cv.put(fLevelUnLocked, "false");
                    cv.put(fLevelBeat, "false");
                    cv.put(fLevelScore, "0");
                            db.insert(tLevels, null, cv);
                    cv.put(fLevelID, 3);
                    cv.put(fLevelUnLocked, "false");
                    cv.put(fLevelBeat, "false");
                    cv.put(fLevelScore, "0");
                            db.insert(tLevels, null, cv);
                    cv.put(fLevelID, 4);
                    cv.put(fLevelUnLocked, "false");
                    cv.put(fLevelBeat, "false");
                    cv.put(fLevelScore, "0");
                            db.insert(tLevels, null, cv);


    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

            db.execSQL("DROP TABLE IF EXISTS "+tLevels);
            onCreate(db);
    }

     public String isLevelUnLocked(int ID) {                 
             SQLiteDatabase myDB = this.getReadableDatabase();
             String[] mySearch = new String[]{String.valueOf(ID)};
             Cursor myCursor = myDB.rawQuery("SELECT "+ fLevelUnLocked +" FROM "+               tLevels +" WHERE "+ fLevelID +"=?",mySearch);
             myCursor.moveToFirst();
             int index = myCursor.getColumnIndex(fLevelUnLocked);
             String myAnswer = myCursor.getString(index);
             myCursor.close();
             myDB.close();
             return myAnswer;
     }

     public String isBeat(int ID) {

                         SQLiteDatabase myDB = this.getReadableDatabase();
                         String[] mySearch = new String[]{String.valueOf(ID)};
                         Cursor myCursor = myDB.rawQuery("SELECT "+ fLevelBeat +" FROM "+ tLevels +" WHERE "+ fLevelID +"=?",mySearch);
                         myCursor.moveToFirst();
                         int index = myCursor.getColumnIndex(fLevelBeat);
                         String myAnswer = myCursor.getString(index);
                         myCursor.close();
                         return myAnswer;
                 }


     public int unLockLevel(int ID, String isUnLocked)
     {
            SQLiteDatabase myDB = this.getWritableDatabase();
             ContentValues cv = new ContentValues();
             cv.put(fLevelUnLocked, isUnLocked);
             int numRowsAffected = myDB.update(tLevels, cv, fLevelID+"=?", new String            []{String.valueOf(ID)});
             return numRowsAffected;
     }




  }

And here is the bit of main activity that I am calling it with

myDatabase myDB = new myDatabase(this);


         final String checkUnLocked = myDB.isLevelUnLocked(4);

         System.out.println(checkUnLocked);
         if(checkUnLocked.compareTo("true") == 0){
         System.out.println("level one is unlocked!");
         }else{
         System.out.println("level one is not unlocked!");
         }
         myDB.close();

And here is the log cat

12-27 13:40:14.896: E/AndEngine(4819): [Debug.java:372:e()]         World1Activity.onCreateScene failed. @(Thread: 'GLThread 13')
12-27 13:40:14.896: E/AndEngine(4819): android.database.CursorIndexOutOfBoundsException: Index 0 requested, with a size of 0
12-27 13:40:14.896: E/AndEngine(4819):  at android.database.AbstractCursor.checkPosition(AbstractCursor.java:580)
12-27 13:40:14.896: E/AndEngine(4819):  at android.database.AbstractWindowedCursor.checkPosition(AbstractWindowedCursor.java:214)
12-27 13:40:14.896: E/AndEngine(4819):  at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:41)
12-27 13:40:14.896: E/AndEngine(4819):  at com.example.test.myDatabase.isLevelUnLocked(myDatabase.java:97)
12-27 13:40:14.896: E/AndEngine(4819):  at com.example.test.World1Activity.onCreateScene(World1Activity.java:159)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateScene(SimpleBaseGameActivity.java:48)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:169)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
12-27 13:40:14.896: E/AndEngine(4819):  at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
12-27 13:40:14.896: E/AndEngine(4819):  at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
12-27 13:40:14.896: E/AndEngine(4819):  at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
12-27 13:40:14.896: D/AndEngine(4819): [Debug.java:218:d()] World1Activity.onSurfaceChanged(Width=800,  Height=480) @(Thread: 'GLThread 13')
12-27 13:40:15.076: E/Database(4819): [SQLiteDatabase.java:1825:finalize()] close() was never explicitly called on database '/data/data/com.example.test/databases/myDB' 
12-27 13:40:15.076: E/Database(4819): android.database.sqlite.DatabaseObjectNotClosedException: Application did not close the cursor or database object that was opened here
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1847)
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:820)
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:854)
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteDatabase.openOrCreateDatabase(SQLiteDatabase.java:847)
12-27 13:40:15.076: E/Database(4819):   at android.app.ContextImpl.openOrCreateDatabase(ContextImpl.java:579)
12-27 13:40:15.076: E/Database(4819):   at android.content.ContextWrapper.openOrCreateDatabase(ContextWrapper.java:203)
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:118)
12-27 13:40:15.076: E/Database(4819):   at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187)
12-27 13:40:15.076: E/Database(4819):   at com.example.test.myDatabase.isLevelUnLocked(myDatabase.java:92)
12-27 13:40:15.076: E/Database(4819):   at com.example.test.World1Activity.onCreateScene(World1Activity.java:159)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateScene(SimpleBaseGameActivity.java:48)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.ui.activity.BaseGameActivity$3.onCreateResourcesFinished(BaseGameActivity.java:169)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.ui.activity.SimpleBaseGameActivity.onCreateResources(SimpleBaseGameActivity.java:43)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.ui.activity.BaseGameActivity.onCreateGame(BaseGameActivity.java:181)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.ui.activity.BaseGameActivity.onSurfaceCreated(BaseGameActivity.java:110)
12-27 13:40:15.076: E/Database(4819):   at org.andengine.opengl.view.EngineRenderer.onSurfaceCreated(EngineRenderer.java:80)
12-27 13:40:15.076: E/Database(4819):   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1348)
12-27 13:40:15.076: E/Database(4819):   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1118)
  • 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-16T13:44:28+00:00Added an answer on June 16, 2026 at 1:44 pm

    Try changing your cursor within isLevelUnlocked(int ID) to the following

    Cursor myCursor = myDb.query(tLevels, new String [] {fLevelID,
    fLevelUnlocked, fLevelBeat, fLevelScore }, fLevelID + “=”
    String.valueOf(ID), null, null, null, null);

    See if that works?

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

Sidebar

Related Questions

Have been working on a Tower Defense game for iOS for some time now.
I have been working with Zend for a few months now and am at
I have been working on a widet for a while now and I have
I am trying to get the channel api working. This is what I have
I have been working a year now as a software developer for a at
I have been working with ASP.NET MVC for a couple of months now and
I have been working on this for hours, but I can't get it to
I have been working with Objective C for a few months now and feel
I have been working on an app for a number of months now and
I have been working on an application in Xcode for a while now and

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.