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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:41:24+00:00 2026-05-29T10:41:24+00:00

I have been having this problem for a few days now, and really cant

  • 0

I have been having this problem for a few days now, and really cant see a problem in the code, so a few extra eyes to have a look is really appreciated.

I start the app by simply creating a new database manager object, and opening the managers database.

 DBManager db_manager = new DBManager(this);
 db_manager.open()

App should then perform a simple insert transaction, but an error is thrown:

02-11 18:13:30.350: E/AndroidRuntime(8961): Caused by: java.lang.NullPointerException
02-11 18:13:30.350: E/AndroidRuntime(8961):     at com.test.DB.DBManager$DatabaseHelper.onCreate(DBManager.java:44)
02-11 18:13:30.350: E/AndroidRuntime(8961):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
02-11 18:13:30.350: E/AndroidRuntime(8961):     at com.test.DB.DBManager.open(DBManager.java:61)
02-11 18:13:30.350: E/AndroidRuntime(8961):     at com.test.DB.Display.onCreate(Display.java:26)
02-11 18:13:30.350: E/AndroidRuntime(8961):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
02-11 18:13:30.350: E/AndroidRuntime(8961):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)

The DatabaseHelper class:

    class DatabaseHelper extends SQLiteOpenHelper{

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

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

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

The DBManager methods, open() is causing the problem.

    public DBManager(Context c){
    this.context = c;
    helper = new DatabaseHelper(context); 
}


// Makes the_db available to the Manager class.
public DBManager open() throws SQLException{
    the_db = helper.getWritableDatabase();
    return this;
}
  • 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-05-29T10:41:24+00:00Added an answer on May 29, 2026 at 10:41 am

    Try :

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

    You already get the database in your onCreate() method, is the SQLiteDatabase parameter db and you must use it.

    EDIT :
    You get the NullPointerException because you call executeSQL() on the_db which is a field in DBManager, probably declared like:

    SQLiteDatabase the_db;
    

    or

    SQliteDatabase the_db = null;
    

    so when you actually get in the onCreate(SQLiteDatabase db) you call executeSQL() on null. The code for DBManager should be something like this:

    public class DBManager {
    
        //the actual database you will use to insert,select etc after the getWritableDatabase() call
        private SQLiteDatabase the_db; 
        private Context context;
        private DatabaseHelper helper;
    
        public DBManager(Context c) {
            this.context = c;
            helper = new DatabaseHelper(context);
        }
    
        // Makes the_db available to the Manager class.
        public DBManager open() throws SQLException {
            the_db = helper.getWritableDatabase();
            return this;
        }
    
        class DatabaseHelper extends SQLiteOpenHelper {
    
            DatabaseHelper(Context context) {
                super(context, "something.db", null, 1);
            }
    
            @Override
            public void onCreate(SQLiteDatabase db) {
                // the db is the SQLiteDatabase that android will offer you
                // and you must use it!
                db.execSQL("CREATE TABLE nametables(name TEXT);");
            }
    
            @Override
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            }
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having some problems with this for a few days now... I
been having this problem for a few days now and can't seem to find
This is a really weird problem that I have been having. When I download
I have been having this problem for some time now, I dont exactly know
After having written a few helper classes in magento, now i have this problem,
Morning, I have been working on this problem for a few days and cannot
I have been trying to tackle this problem , but I am having difficulty
Hello I have been having trouble with this for a while now. I have
I've been doing web development for a few months now and keep having this
This one has been driving me nuts for a few days now and I've

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.