I'm following Android developers tutorial to set up a database but i'm having an issue .
https://developer.android.com/training/basics/data-storage/databases.html
This is my schema file :
public final class ContactsDBSchema {
public ContactsDBSchema(){};
public static abstract class ContactsEntry implements BaseColumns
{
public static final String TABLE_NAME = "contacts";
public static final String COLUMN_CONTACT__ID = "contact_id";
public static final String COLUMN_CONTACT__NAME = "contact_name";
public static final String COLUMN_CONTACT__PHONE = "contact_phone";
}
public class ContactsDBhelper extends SQLiteOpenHelper
{
public static final int DATABASE_VERSION = 1;
public static final String DATABASE_NAME = "contacts.db";
public String SQL_CREATE_ENTRIES = "create table" + ContactsEntry.TABLE_NAME + ContactsEntry.COLUMN_CONTACT__ID +"INTEGER PRIMARY KEY AUTOINCREMENT," + ContactsEntry.COLUMN_CONTACT__NAME + "TEXT," + ContactsEntry.COLUMN_CONTACT__PHONE + "TEX";
public String SQL_DELETE_ENTRIES = "DROP TABLE IF EXISTS" + ContactsEntry.TABLE_NAME ;
public ContactsDBhelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
public void onCreate(SQLiteDatabase db) {
db.execSQL(SQL_CREATE_ENTRIES);
}
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(SQL_DELETE_ENTRIES);
onCreate(db);
}
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
onUpgrade(db, oldVersion, newVersion);
}
}
}
The issue now is when i'm trying to access it from another class .
public class ContactsDBprocess {
ContactsDBSchema.ContactsDBhelper contactsHelper = new ContactsDBSchema.ContactsDBhelper(getContext());
}
First , i'm unable to access the DBhelper problerly .
second , the getContext() does not work (Caot resolve method getContext)
i tried :
ContactsDBSchema.ContactsDBhelper contactsHelper = new ContactsDBSchema.ContactsDBhelper(this)
ContactsDBSchema.ContactsDBhelper contactsHelper = new ContactsDBSchema.ContactsDBhelper(getApplicationContext())
