0
    Code :

        public void onCreate(SQLiteDatabase db) {
                    // TODO Auto-generated method stub
                    RegistrationPage var = new RegistrationPage();
                    DATABASE_TABLE =  var.username.getText().toString();

                    db.execSQL(" CREATE TABLE " + DATABASE_TABLE + " (" + KEY_FIRSTNAME
                            + " TEXT NOT NULL, " + KEY_MIDDLENAME
                            + " TEXT NOT NULL, " + KEY_LASTNAME + " TEXT NOT NULL, " + KEY_USERNAME + " TEXT NOT NULL, " + KEY_MAIL_ID + " TEXT NOT NULL, " + KEY_DATE_OF_BIRTH + " INTEGER NOT NULL, " + KEY_COUNTRY + " TEXT NOT NULL " + ");");

The above code represents the method from DBAdapter class where i initialize and do all the activities in database.

I have 3 activities

  1. SignIn
  2. Register
  3. View

SignIn : Not concentrating on it as of now.

Register : In this page, i get the details of the user including the USERNAME WHICH SHOULD SET AS THE NAME FOR THE TABLE IN MY DATABASE. Then i open it and insert all the data into the database.

NOTE : Inserting the data doesn't work while i assign the table name dynamically but if i hardcode the table name then it works like a charm

View : While viewing, i need to open the database first which would require the table name that i assigned in the previous activity but it says null pointer exception while moving to this activity and force closes my application.

Help me guys. I am newbie and desperate about this project.

3
  • I had to get the instance of RegistrationPage in all the methods to access the DATABASE_TABLE name. Methods like onCreate(),onUpdate(),onInsert() and so on. Commented Dec 5, 2013 at 7:45
  • Why don't you use a single "Users" table, with the user name as an extra column? Commented Dec 5, 2013 at 8:22
  • @CL, Thats what i am going to do. Thanks for your help. Commented Dec 5, 2013 at 8:41

1 Answer 1

2

Its better to store the table name in some storage i.e: SharedPreferences and use it for creating , fetching, inserting, updating your table.

Sign up to request clarification or add additional context in comments.

5 Comments

You mean that i get the username and assign it to shared preference and then use it across all the meethods ??
yes, this is the better way because if you are using database its obvious that your application will use the database in future also when you close the application and come back to use it!
Thanks pal. Much appreciated. Will try that and get back to ya !!
SharedPreferences sp = getSharedPreferences("Prefs",MODE_PRIVATE); String et_string = sp.getString("database_tabel",var.username.getText().toString()); Will this work ?
You should check out how to insert and fetch data from SharedPreferences :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.