user6656800 user6656800 - 3 months ago 7
Android Question

How to use SQLiteOpenHelper variables in other classes in Android

In my

SQLiteOpenHelder
class i have some variables, and I want use this variables in other classes. but when call
SQLiteOpenHelper
in other classes, not show me variables of this class (
SQLiteOpenHelper
)!


SQLiteOpenHelper codes:

public class databaseHelper {

static class Helper extends SQLiteOpenHelper {

private Context context;

private static final String DATABASE_NAME = "slidenerd_database";
private static final String DATABASE_TABLE = "USER_TABLE";
// If Table was changed, version should up number
private static final int DATABASE_VERSION = 5;
private static final String User_UID = "user_id";
private static final String User_NAME = "user_name";
private static final String USER_PASSWORD = "user_password";
// CREATE QUERY
private static final String CREATE_TABLE = "CREATE TABLE " + DATABASE_TABLE + " (" + User_UID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
" " + User_NAME + " VARCHAR(50), " + USER_PASSWORD + " VARCHAR(50));";
// DROP QUERY
private static final String DROP_TABLE = "DROP TABLE IF EXISTS " + DATABASE_TABLE;

// Constructor
public Helper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
this.context = context;
CustomToast.ToastMessage(context, "Constructor called");
}

// If create table for first time
@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {

try {
sqLiteDatabase.execSQL(CREATE_TABLE);
CustomToast.ToastMessage(context, "onCreate called");
} catch (SQLException e) {
CustomToast.ToastMessage(context, "" + e);
}
}

// If table has updated
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {
try {
CustomToast.ToastMessage(context, "onUpgrade called");
sqLiteDatabase.execSQL(DROP_TABLE);
onCreate(sqLiteDatabase);

} catch (SQLException e) {
CustomToast.ToastMessage(context, "" + e);
}
}
}
}


Other class :

public class databaseAdapter {

private databaseHelper.Helper helper;

public databaseAdapter(Context context) {
helper = new databaseHelper.Helper(context);
}

public void insert(String name, String password) {

SQLiteDatabase database = helper.getWritableDatabase();

ContentValues contentValues = new ContentValues();
contentValues.put(databaseHelper.Helper);
}

}


When write . (dot) after
databaseHelper.Helper
, not show me variables of this class !

How can I fix this?

Answer

You must set public for your variables.
Such as :

public static final String User_UID = "user_id";