I am working on a notepad application in java. After initializing the database in RoomDB.java class, i am importing the values in my MainDAO.java interface to perform Datebase logics. However, i get following errors in my Problems box of my MainDAO.java file: Here Cannot resolve symbol 'ID' Cannot resolve symbol 'notes' Cannot resolve symbol 'title' Cannot resolve symbol 'notes'
I am still learning to develop apps in android studio so please guide me and let me know the cause of the error. Following are the code files for your reference, let me know if you need anything else to debug this error.
MainDAO.java
package com.example.notepad_colornotes.Database;
import static androidx.room.OnConflictStrategy.REPLACE;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import com.example.notepad_colornotes.Models.Notes;
import java.util.List;
@Dao
public interface MainDAO {
//method to insert data into our database
@Insert(onConflict = REPLACE)
void insert(Notes notes);
//method to get all the data, datatype is list
@Query("SELECT * FROM notes ORDER BY ID DESC") //this query arranges the items in the notes in descending order. newly added ones will be at the top
List<Notes> getAll();
//method to update the data
@Query("UPDATE notes SET title = :Title, notes = :Notes WHERE ID = :ID") //takes the value from the model and that of the update method parameter
void update(int ID, String Title, String Notes);
@Delete
void delete(Notes notes);
}
RoomDB.java
package com.example.notepad_colornotes.Database;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import com.example.notepad_colornotes.Models.Notes;
@Database(entities = Notes.class, version = 1, exportSchema = false)
public abstract class RoomDB extends RoomDatabase {
private static RoomDB database;
private static String DATABASE_NAME = "NoteApp";
//method to get the instance of the database
public synchronized static RoomDB getInstance(Context context){
if (database == null){
database = Room.databaseBuilder(context.getApplicationContext(),
RoomDB.class, DATABASE_NAME)
.allowMainThreadQueries()
.fallbackToDestructiveMigration()
.build();
}
return database;
}
//instance of DAO
public abstract MainDAO mainDAO();
}
Notes.java
package com.example.notepad_colornotes.Models;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import java.io.Serializable;
//Serialization in Java allows us to convert an Object to stream that we can send over the network or save it as file or store in DB for later usage
@Entity(tableName = "notes")
@SuppressWarnings("unused")
public class Notes implements Serializable {
@PrimaryKey(autoGenerate = true) //automatically generates an ID whenever we add an item
int ID = 0;
@ColumnInfo(name = "title")
String Title = "";
@ColumnInfo(name = "notes")
String Notes = "";
@ColumnInfo(name = "date")
String Date = "";
@ColumnInfo(name = "pinned")
boolean Pinned = false;
public int getID() {
return ID;
}
public void setID(int ID) {
this.ID = ID;
}
public String getTitle() {
return Title;
}
public void setTitle(String title) {
this.Title = title;
}
public String getNotes() {
return Notes;
}
public void setNotes(String notes) {
this.Notes = notes;
}
public String getDate() {
return Date;
}
public void setDate(String date) {
this.Date = date;
}
public boolean isPinned() {
return Pinned;
}
public void setPinned(boolean pinned) {
this.Pinned = pinned;
}
}
i have tried making the compilersdkversion to 33 as well and i have also rebuilt the project also i have checked the imports and the case sensitivity of the values. still no use