The error message "Can't determine type for tag '<application ...>'" typically occurs when your AndroidManifest.xml is malformed or an XML tag is used incorrectly, often in an Android Layout XML instead of the manifest.
This is a portion of your AndroidManifest.xml. The <application> tag must be a child of the root <manifest> tag. If you try to include this fragment in a layout XML or somewhere else, the parser tries to interpret <application> as a UI widget and fails to determine its type.
Common causes:
Using manifest content in layout XML or elsewhere:
Make sure this snippet is inside your AndroidManifest.xml file, and not in a layout XML (e.g., activity_main.xml) or other resource files.
public class DatabaseHelper extends SQLiteOpenHelper {
code
Assistant
Got it! You want help to:
Review and fix/improve your DatabaseHelper class (you posted a partial/fragmented version).
Create or update an EditProfileActivity that works with this database helper for editing user details.
Step 1: Cleaned & Full DatabaseHelper
You have some duplicated getAllRooms() methods in your snippet; also some lines seem out of place (possibly copypasta). I'll clean it and provide a complete fixed version with all key methods (insertUser, userExists, authenticateUser, getUserByEmail, updateUser, and getAllRooms.)
java
User
i dont change databasehelper file editproflleactivity only
Assistant
Understood! You want only the EditProfileActivity code that works with your existing DatabaseHelper as is, without changing it.
Here’s a complete minimal EditProfileActivity implementation assuming your current DatabaseHelper methods getUserByEmail(String email) and updateUser(User user) exist as you posted.
EditProfileActivity.java
java
package com.luxevistaresortapp.activities;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.luxevistaresortapp.R;
import com.luxevistaresortapp.helpers.DatabaseHelper;
import com.luxevistaresortapp.models.User;
public class EditProfileActivity extends AppCompatActivity {
private EditText etName, etPreferences;
private Button btnSave;
private DatabaseHelper dbHelper;
private User currentUser;
private String userEmail; // Passed via Intent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
etName = findViewById(R.id.etName);
etPreferences = findViewById(R.id.etPreferences);
btnSave = findViewById(R.id.btnSave);
dbHelper = new DatabaseHelper(this);
// Get user email from intent (make sure you pass this extra on Activity start)
userEmail = getIntent().getStringExtra("user_email");
if (userEmail == null) {
Toast.makeText(this, "No user email provided", Toast.LENGTH_SHORT).show();
finish();
return;
}
loadUserProfile();
btnSave.setOnClickListener(v -> saveProfile());
}
private void loadUserProfile() {
currentUser = dbHelper.getUserByEmail(userEmail);
if (currentUser != null) {
etName.setText(currentUser.getName());
etPreferences.setText(currentUser.getPreferences());
} else {
Toast.makeText(this, "User not found", Toast.LENGTH_SHORT).show();
finish();
}
}
private void saveProfile() {
String newName = etName.getText().toString().trim();
String newPreferences = etPreferences.getText().toString().trim();
if (TextUtils.isEmpty(newName)) {
etName.setError("Name cannot be empty");
return;
}
currentUser.setName(newName);
currentUser.setPreferences(newPreferences);
boolean updated = dbHelper.updateUser(currentUser);
if (updated) {
Toast.makeText(this, "Profile updated successfully", Toast.LENGTH_SHORT).show();
finish(); // close the activity or navigate as needed
} else {
Toast.makeText(this, "Failed to update profile", Toast.LENGTH_SHORT).show();
}
}
}
User
Cannot resolve method 'getUserByEmail' in 'DatabaseHelper' Cannot resolve method 'updateUser' in 'DatabaseHelper'
Assistant
The errors:
code
Cannot resolve method 'getUserByEmail' in 'DatabaseHelper'
Cannot resolve method 'updateUser' in 'DatabaseHelper'
mean that in your current DatabaseHelper class those two methods do not exist or are not public.
What to do
Double-check your DatabaseHelper class
Make sure it includes the following two methods, exactly like this, and they have public visibility:
java
// Get user by email (no password)
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Update user profile (name and preferences)
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rows = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rows > 0;
}
public class EditProfileActivity extends AppCompatActivity {
code
private EditText etName, etPreferences;
private Button btnSave;
private DatabaseHelper dbHelper;
private User currentUser;
private String userEmail; // Passed via Intent
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit_profile);
etName = findViewById(R.id.etName);
etPreferences = findViewById(R.id.etPreferences);
btnSave = findViewById(R.id.btnSave);
dbHelper = new DatabaseHelper(this);
// Get user email from intent (make sure you pass this extra on Activity start)
userEmail = getIntent().getStringExtra("user_email");
if (userEmail == null) {
Toast.makeText(this, "No user email provided", Toast.LENGTH_SHORT).show();
finish();
return;
}
loadUserProfile();
btnSave.setOnClickListener(v -> saveProfile());
}
private void loadUserProfile() {
currentUser = dbHelper.getUserByEmail(userEmail);
if (currentUser != null) {
etName.setText(currentUser.getName());
etPreferences.setText(currentUser.getPreferences());
} else {
Toast.makeText(this, "User not found", Toast.LENGTH_SHORT).show();
finish();
}
}
private void saveProfile() {
String newName = etName.getText().toString().trim();
String newPreferences = etPreferences.getText().toString().trim();
if (TextUtils.isEmpty(newName)) {
etName.setError("Name cannot be empty");
return;
}
currentUser.setName(newName);
currentUser.setPreferences(newPreferences);
boolean updated = dbHelper.updateUser(currentUser);
if (updated) {
Toast.makeText(this, "Profile updated successfully", Toast.LENGTH_SHORT).show();
finish(); // close the activity or navigate as needed
} else {
Toast.makeText(this, "Failed to update profile", Toast.LENGTH_SHORT).show();
}
}
Assistant
Thanks for sharing the full code! The problem is clear now:
Your current DatabaseHelperdoes NOT have the methods getUserByEmail(String email) or updateUser(User user) implemented, but your EditProfileActivity tries to call those methods.
To fix this error:
You need to add the required methods to your DatabaseHelper class.
Add these two methods inside your DatabaseHelper class:
java
// Get user details by email (no password check)
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Update user profile in the DB
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rowsAffected = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rowsAffected > 0;
}
User
fulll code give
Assistant
Certainly! Here's your complete DatabaseHelper.java with the necessary methods getUserByEmail and updateUser added, integrated properly with your existing code:
java
User
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
code
int rowsAffected = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rowsAffected > 0;
} add thsi part only databasehelper plz
Assistant
Certainly! Here's the updateUser method ready to be added to your existing DatabaseHelper class:
java
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rowsAffected = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rowsAffected > 0;
}
How to add:
Open your DatabaseHelper class.
Paste this method anywhere inside the class but outside other methods.
Save and rebuild your project.
Now your DatabaseHelper will support updating user profiles!
public class DatabaseHelper extends SQLiteOpenHelper {
code
Assistant
Certainly! Below is your updated DatabaseHelper class with the getUserByEmail and updateUser methods added. Place these methods inside the class (after the existing methods or before getAllRooms):
java
// Get user details by email
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Update user profile (name and preferences)
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rowsAffected = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rowsAffected > 0;
}
User
DatabaseHelper full code
Assistant
Certainly! Here's the full DatabaseHelper class with the two requested methods (getUserByEmail and updateUser) added and integrated with your existing code:
public class DatabaseHelper extends SQLiteOpenHelper {
code
private static final String DATABASE_NAME = "LuxeVistaResort.db";
private static final int DATABASE_VERSION = 1;
// Table and columns - Users
private static final String TABLE_USERS = "users";
private static final String USER_ID = "id";
private static final String USER_NAME = "name";
private static final String USER_EMAIL = "email";
private static final String USER_PASSWORD = "password";
private static final String USER_PREFERENCES = "preferences";
// Table and columns - Rooms
private static final String TABLE_ROOMS = "rooms";
private static final String ROOM_ID = "id";
private static final String ROOM_TYPE = "type";
private static final String ROOM_DESC = "description";
private static final String ROOM_PRICE = "price";
private static final String ROOM_IMAGE = "image";
// Tables for bookings, services... (add similarly)
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Users table
String createUsers = "CREATE TABLE " + TABLE_USERS + " ("
+ USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ USER_NAME + " TEXT NOT NULL, "
+ USER_EMAIL + " TEXT NOT NULL UNIQUE, "
+ USER_PASSWORD + " TEXT NOT NULL, "
+ USER_PREFERENCES + " TEXT"
+ ");";
// Rooms table
String createRooms = "CREATE TABLE " + TABLE_ROOMS + " ("
+ ROOM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ROOM_TYPE + " TEXT, "
+ ROOM_DESC + " TEXT, "
+ ROOM_PRICE + " REAL, "
+ ROOM_IMAGE + " TEXT"
+ ");";
// Create tables
db.execSQL(createUsers);
db.execSQL(createRooms);
// Insert sample rooms
db.execSQL("INSERT INTO " + TABLE_ROOMS + " (" + ROOM_TYPE + "," + ROOM_DESC + "," + ROOM_PRICE + "," + ROOM_IMAGE + ") VALUES" +
"('Deluxe Suite', 'Ocean view with king size bed', 350.00, 'deluxe_suite.jpg')," +
"('Standard Room', 'Garden view with queen size bed', 180.00, 'standard_room.jpg')," +
"('Cabana', 'Beachfront cabana with private deck', 500.00, 'cabana.jpg')"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop tables if needed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ROOMS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
// User insert/check/authenticate methods (as before) ...
// ...
// Example: getAllRooms method
public List<Room> getAllRooms() {
List<Room> roomList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ROOMS, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Room room = new Room();
room.setId(cursor.getInt(cursor.getColumnIndexOrThrow(ROOM_ID)));
room.setType(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_TYPE)));
room.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_DESC)));
room.setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(ROOM_PRICE)));
room.setImage(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_IMAGE)));
roomList.add(room);
} while (cursor.moveToNext());
}
cursor.close();
return roomList;
}
// Other CRUD methods for bookings, services, users, etc.
} dtabasehelper debug it
Where to place these methods
Put these inside your existing DatabaseHelper class (somewhere near other CRUD methods):
java
// ... your existing code ...
// Add here
public User getUserByEmail(String email) {
// ...method as above...
}
public boolean updateUser(User user) {
// ...method as above...
}
// ... any other methods ...
Why are these needed?
getUserByEmail: retrieves the User object from the database so you can display existing data for editing.
updateUser: saves the updated name and preferences back to the database.
Without these, your EditProfileActivity can't function.
Summary:
Your DatabaseHelper currently misses these methods.
Add them as above.
Clean and rebuild your project.
Your EditProfileActivity should then compile and work correctly.
If you want, I can provide the full updated DatabaseHelper.java with these methods added. Just ask!
package com.luxevistaresortapp.helpers;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.luxevistaresortapp.models.User;
import com.luxevistaresortapp.models.Room;
import java.util.ArrayList;
import java.util.List;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "LuxeVistaResort.db";
private static final int DATABASE_VERSION = 1;
// Table and columns - Users
private static final String TABLE_USERS = "users";
private static final String USER_ID = "id";
private static final String USER_NAME = "name";
private static final String USER_EMAIL = "email";
private static final String USER_PASSWORD = "password";
private static final String USER_PREFERENCES = "preferences";
// Table and columns - Rooms
private static final String TABLE_ROOMS = "rooms";
private static final String ROOM_ID = "id";
private static final String ROOM_TYPE = "type";
private static final String ROOM_DESC = "description";
private static final String ROOM_PRICE = "price";
private static final String ROOM_IMAGE = "image";
// Tables for bookings, services... (add similarly)
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Users table
String createUsers = "CREATE TABLE " + TABLE_USERS + " ("
+ USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ USER_NAME + " TEXT NOT NULL, "
+ USER_EMAIL + " TEXT NOT NULL UNIQUE, "
+ USER_PASSWORD + " TEXT NOT NULL, "
+ USER_PREFERENCES + " TEXT"
+ ");";
// Rooms table
String createRooms = "CREATE TABLE " + TABLE_ROOMS + " ("
+ ROOM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ROOM_TYPE + " TEXT, "
+ ROOM_DESC + " TEXT, "
+ ROOM_PRICE + " REAL, "
+ ROOM_IMAGE + " TEXT"
+ ");";
// Create tables
db.execSQL(createUsers);
db.execSQL(createRooms);
// Insert sample rooms
db.execSQL("INSERT INTO " + TABLE_ROOMS + " (" + ROOM_TYPE + "," + ROOM_DESC + "," + ROOM_PRICE + "," + ROOM_IMAGE + ") VALUES" +
"('Deluxe Suite', 'Ocean view with king size bed', 350.00, 'deluxe_suite.jpg')," +
"('Standard Room', 'Garden view with queen size bed', 180.00, 'standard_room.jpg')," +
"('Cabana', 'Beachfront cabana with private deck', 500.00, 'cabana.jpg')"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop tables if needed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ROOMS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
// Insert a new user
public boolean insertUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_EMAIL, user.getEmail());
cv.put(USER_PASSWORD, user.getPassword());
cv.put(USER_PREFERENCES, user.getPreferences());
long result = db.insert(TABLE_USERS, null, cv);
db.close();
return result != -1;
}
// Check if user exists by email
public boolean userExists(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
boolean exists = cursor != null && cursor.getCount() > 0;
if (cursor != null) cursor.close();
return exists;
}
// Authenticate user by email + password
public User authenticateUser(String email, String password) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=? AND " + USER_PASSWORD + "=?",
new String[]{email, password},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Get user details by email
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Update user profile (name and preferences)
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rows = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rows > 0;
}
// Get all rooms for browsing
public List<Room> getAllRooms() {
List<Room> roomList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ROOMS, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Room room = new Room();
room.setId(cursor.getInt(cursor.getColumnIndexOrThrow(ROOM_ID)));
room.setType(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_TYPE)));
room.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_DESC)));
room.setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(ROOM_PRICE)));
room.setImage(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_IMAGE)));
roomList.add(room);
} while (cursor.moveToNext());
}
cursor.close();
return roomList;
}
// You can add other CRUD methods for bookings, services, users, etc.
}
What changed?
Added complete code for getUserByEmail(String email) — loads user data from DB.
Added updateUser(User user) — updates the user's name and preferences.
Included method headers for insertUser, userExists, authenticateUser for completeness, assuming you may have those or want to add them.
Your existing methods untouched, just completed the missing parts.
After this:
Your EditProfileActivity code will compile and work without Cannot resolve method errors.
You can load and update user profiles via your DatabaseHelper.
Feel free to ask if you want me to provide more helper methods or activity examples!
private static final String DATABASE_NAME = "LuxeVistaResort.db";
private static final int DATABASE_VERSION = 1;
// Table and columns - Users
private static final String TABLE_USERS = "users";
private static final String USER_ID = "id";
private static final String USER_NAME = "name";
private static final String USER_EMAIL = "email";
private static final String USER_PASSWORD = "password";
private static final String USER_PREFERENCES = "preferences";
// Table and columns - Rooms
private static final String TABLE_ROOMS = "rooms";
private static final String ROOM_ID = "id";
private static final String ROOM_TYPE = "type";
private static final String ROOM_DESC = "description";
private static final String ROOM_PRICE = "price";
private static final String ROOM_IMAGE = "image";
// Tables for bookings, services... (add similarly)
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Users table
String createUsers = "CREATE TABLE " + TABLE_USERS + " ("
+ USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ USER_NAME + " TEXT NOT NULL, "
+ USER_EMAIL + " TEXT NOT NULL UNIQUE, "
+ USER_PASSWORD + " TEXT NOT NULL, "
+ USER_PREFERENCES + " TEXT"
+ ");";
// Rooms table
String createRooms = "CREATE TABLE " + TABLE_ROOMS + " ("
+ ROOM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ROOM_TYPE + " TEXT, "
+ ROOM_DESC + " TEXT, "
+ ROOM_PRICE + " REAL, "
+ ROOM_IMAGE + " TEXT"
+ ");";
// Create tables
db.execSQL(createUsers);
db.execSQL(createRooms);
// Insert sample rooms
db.execSQL("INSERT INTO " + TABLE_ROOMS + " (" + ROOM_TYPE + "," + ROOM_DESC + "," + ROOM_PRICE + "," + ROOM_IMAGE + ") VALUES" +
"('Deluxe Suite', 'Ocean view with king size bed', 350.00, 'deluxe_suite.jpg')," +
"('Standard Room', 'Garden view with queen size bed', 180.00, 'standard_room.jpg')," +
"('Cabana', 'Beachfront cabana with private deck', 500.00, 'cabana.jpg')"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop tables if needed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ROOMS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
// User insert/check/authenticate methods (as before) ...
// ...
// Example: getAllRooms method
public List<Room> getAllRooms() {
List<Room> roomList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ROOMS, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Room room = new Room();
room.setId(cursor.getInt(cursor.getColumnIndexOrThrow(ROOM_ID)));
room.setType(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_TYPE)));
room.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_DESC)));
room.setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(ROOM_PRICE)));
room.setImage(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_IMAGE)));
roomList.add(room);
} while (cursor.moveToNext());
}
cursor.close();
return roomList;
}
// Other CRUD methods for bookings, services, users, etc.
} add pls
How the full class would look with these methods added (only showing additions):
java
public class DatabaseHelper extends SQLiteOpenHelper {
// ... your existing code ...
// Add this method inside the class
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Add this method inside the class
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rowsAffected = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rowsAffected > 0;
}
// ... your existing methods like getAllRooms() ...
}
Add these two methods to your current DatabaseHelper class, rebuild your project, and your EditProfileActivity will be able to use them without errors.
package com.luxevistaresortapp.helpers;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import com.luxevistaresortapp.models.User;
import com.luxevistaresortapp.models.Room;
import java.util.ArrayList;
import java.util.List;
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "LuxeVistaResort.db";
private static final int DATABASE_VERSION = 1;
// Table and columns - Users
private static final String TABLE_USERS = "users";
private static final String USER_ID = "id";
private static final String USER_NAME = "name";
private static final String USER_EMAIL = "email";
private static final String USER_PASSWORD = "password";
private static final String USER_PREFERENCES = "preferences";
// Table and columns - Rooms
private static final String TABLE_ROOMS = "rooms";
private static final String ROOM_ID = "id";
private static final String ROOM_TYPE = "type";
private static final String ROOM_DESC = "description";
private static final String ROOM_PRICE = "price";
private static final String ROOM_IMAGE = "image";
// Tables for bookings, services... (add similarly)
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
// Users table
String createUsers = "CREATE TABLE " + TABLE_USERS + " ("
+ USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ USER_NAME + " TEXT NOT NULL, "
+ USER_EMAIL + " TEXT NOT NULL UNIQUE, "
+ USER_PASSWORD + " TEXT NOT NULL, "
+ USER_PREFERENCES + " TEXT"
+ ");";
// Rooms table
String createRooms = "CREATE TABLE " + TABLE_ROOMS + " ("
+ ROOM_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ ROOM_TYPE + " TEXT, "
+ ROOM_DESC + " TEXT, "
+ ROOM_PRICE + " REAL, "
+ ROOM_IMAGE + " TEXT"
+ ");";
// Create tables
db.execSQL(createUsers);
db.execSQL(createRooms);
// Insert sample rooms
db.execSQL("INSERT INTO " + TABLE_ROOMS + " (" + ROOM_TYPE + "," + ROOM_DESC + "," + ROOM_PRICE + "," + ROOM_IMAGE + ") VALUES" +
"('Deluxe Suite', 'Ocean view with king size bed', 350.00, 'deluxe_suite.jpg')," +
"('Standard Room', 'Garden view with queen size bed', 180.00, 'standard_room.jpg')," +
"('Cabana', 'Beachfront cabana with private deck', 500.00, 'cabana.jpg')"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop tables if needed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_ROOMS);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
onCreate(db);
}
// Insert a new user
public boolean insertUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_EMAIL, user.getEmail());
cv.put(USER_PASSWORD, user.getPassword());
cv.put(USER_PREFERENCES, user.getPreferences());
long result = db.insert(TABLE_USERS, null, cv);
db.close();
return result != -1;
}
// Check if a user exists by email
public boolean userExists(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
boolean exists = (cursor != null && cursor.getCount() > 0);
if (cursor != null) cursor.close();
return exists;
}
// Authenticate user by email and password
public User authenticateUser(String email, String password) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=? AND " + USER_PASSWORD + "=?",
new String[]{email, password},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Get user details by email
public User getUserByEmail(String email) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_USERS,
new String[]{USER_ID, USER_NAME, USER_EMAIL, USER_PASSWORD, USER_PREFERENCES},
USER_EMAIL + "=?",
new String[]{email},
null, null, null);
User user = null;
if (cursor != null && cursor.moveToFirst()) {
user = new User();
user.setId(cursor.getInt(cursor.getColumnIndexOrThrow(USER_ID)));
user.setName(cursor.getString(cursor.getColumnIndexOrThrow(USER_NAME)));
user.setEmail(cursor.getString(cursor.getColumnIndexOrThrow(USER_EMAIL)));
user.setPassword(cursor.getString(cursor.getColumnIndexOrThrow(USER_PASSWORD)));
user.setPreferences(cursor.getString(cursor.getColumnIndexOrThrow(USER_PREFERENCES)));
cursor.close();
}
return user;
}
// Update a user's profile (name and preferences)
public boolean updateUser(User user) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(USER_NAME, user.getName());
cv.put(USER_PREFERENCES, user.getPreferences());
int rows = db.update(TABLE_USERS, cv, USER_ID + "=?", new String[]{String.valueOf(user.getId())});
db.close();
return rows > 0;
}
// Fetch all rooms available
public List<Room> getAllRooms() {
List<Room> roomList = new ArrayList<>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(TABLE_ROOMS, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Room room = new Room();
room.setId(cursor.getInt(cursor.getColumnIndexOrThrow(ROOM_ID)));
room.setType(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_TYPE)));
room.setDescription(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_DESC)));
room.setPrice(cursor.getDouble(cursor.getColumnIndexOrThrow(ROOM_PRICE)));
room.setImage(cursor.getString(cursor.getColumnIndexOrThrow(ROOM_IMAGE)));
roomList.add(room);
} while (cursor.moveToNext());
}
cursor.close();
return roomList;
}
// Add more CRUD methods for bookings, services, etc. as needed.
}
This version includes:
User CRUD methods: insert, exists, authenticate, get by email, update
Room retrieval (getAllRooms)
Your existing table creation & upgrades
The two methods (getUserByEmail and updateUser) you requested, so your EditProfileActivity will work correctly.
If you want any further help with activities or other parts, feel free to ask!