0

For example:
If I create a list people and that list contains Name, Age, Height as the elements, then a Table of Name People will be created, having the columns Name, Age, Height

I tried this code...

static final String DATABASE_NAME="MyDatabase";
    static final int DATABASE_VERSION = 1;
    static String TABLE_NAME=null;
    static String CREATE_TABLE = null;
    static List<String> COLUMNS = null;
    static String DROP_TABLE = null;

    private Context context;

    public DBHandler(Context context,String Table_Name,List<String> columns,){
        super(context,DATABASE_NAME,null,DATABASE_VERSION);
        this.context = context;
        this.TABLE_NAME=Table_Name;
        this.COLUMNS = columns;
        CREATE_TABLE ="CREATE TABLE "+TABLE_NAME+"("+COLUMNS.get(0)+" INTEGER PRIMARY KEY, "+COLUMNS.get(1)+" TEXT,"+COLUMNS.get(2)+" TEXT,"+COLUMNS.get(3)+" TEXT,"+COLUMNS.get(4)+" TEXT)";
        DROP_TABLE = "DROP TABLE IF EXISTS "+TABLE_NAME;
    }
    public DBHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, DATABASE_NAME, factory, DATABASE_VERSION);
        this.context=context;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_TABLE);
    }
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • 2
    And what happened when you tried this code? – Rabbit Guy Aug 11 '16 at 20:21
  • No output,No logs....couldnt trace the results – user3807098 Aug 11 '16 at 20:34
  • I'm sorry, but where is there supposed to be output here? I don't see this outputing anything – Rabbit Guy Aug 11 '16 at 20:36
  • I have textViews in other Activity which shows the results...i havent given the output part here....but i'm sure there is nothing wrong in the output part.... – user3807098 Aug 11 '16 at 20:38
  • 1
    Did you actually create the database? Your code only seems to be called upon its creation. – johnnyaug Aug 11 '16 at 21:06
  • Just a personal suggestion (and it's just me), I wouldn't be diving into database manipulation at this level. Do simple database manipulation first just so you know how to get, insert, delete, and update tables first before you get into Activities and android development. – Rabbit Guy Aug 11 '16 at 21:11
  • @johnnyaug this is not the entire code....its only a part of the code in Database handler class – user3807098 Aug 11 '16 at 21:26
  • Did you make sure your code is actually running? Once you've done that, put it in a `try-catch`, perhaps an exception is thrown. – johnnyaug Aug 11 '16 at 21:43
  • Yes I've tried the code....It shows a NullPointerException – user3807098 Aug 12 '16 at 05:37

0 Answers0