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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:30:32+00:00 2026-05-31T03:30:32+00:00

Following on from my previous question about tables I am trying to create additional

  • 0

Following on from my previous question about tables I am trying to create additional tables on my database in Android.

Basically, I would like a database to be created which is done so by this code:

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

Then when a user adds an account I would like a table added with the name of the account the user entered. I try to call the createTable() method I created.

 public void createAccount(String account) {
        DATABASE_TABLE = account;
        db.execSQL(TABLE_CREATE);
        System.out.println(DATABASE_NAME);      
}

But the db doesn’t work as eclipse cannot find the variable. I try mDb which is my SQLiteDatabase but I get a null pointer exception.

*Edit*

I really can’t get my head around the database. I am using the For Dummies book and a Database helper but from where I am at now I feel a lot of the code is done behind the scenes and it is hard to follow.

This is part of my database class:

private static class DatabaseHelper extends SQLiteOpenHelper {

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


    public void onCreate(SQLiteDatabase db) {
        System.out.println(DATABASE_TABLE);
        db.execSQL(TABLE_CREATE);
    }

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

    public void createAccount(String account) {
        DATABASE_TABLE = account;
        /*   SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL("create table long ("
                + KEY_ROWID + " integer primary key autoincrement, "
                + KEY_DESCRIPTION + " text not null, " 
                + KEY_DEBIT + " text not null);");   
    }       
}

At the bottom of the class I have

public void changeDatabase(String account) {
    DATABASE_TABLE = account;
    mDbHelper.createAccount(account);
}

which is called upon from my createAccount class.

I am getting a null point exception.

  • 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-31T03:30:34+00:00Added an answer on May 31, 2026 at 3:30 am

    This is without seeing your code…

    I’m guessing you’ve inherited / extended from one of the SQLite Classes.

    you see how you’ve implemented onCreate() and are provided the database as a parameter,

    if you create a new function, like that createAccount function you need to get a handle of the db as follows:-

     public void createAccount(String account) {
        DATABASE_TABLE = account;
        SQLiteDatabase db = this.getWritableDatabase();
        db.execSQL(TABLE_CREATE);
        System.out.println(DATABASE_NAME);      
    }
    
    • Anthony
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following on from a previous question about sub-selects, I have an SQL statement with
me again. Sorry about this. Following on from my previous question (I think I
Following on from my previous question , is it possible to make a Python
Following on from my previous question [link text][1] , I have a new problem.
Following up from my previous question , why is CShell so different from C?
Following on from a previous question, for some reason when I use the following
Following on from a previous question relating to heap usage restrictions , I'm looking
Following on from a previous question , I am creating a symbolic link on
Okay, this is following on from my previous question reguarding performing a simple ajax
This problem follows on from a previous question . When I run the following

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.