I'm trying to save my images using room database.
Saving is not working. I guess my DAO class does not recognize the table name and id. Can you review the following pictures and help me to solve this issue?
@Entity(tableName = "my_images")
public class MyImagesEntity {
@PrimaryKey(autoGenerate = true)
public int image_id;
public String image_title;
public String image_description;
//images/sounds are stored in database as binary large object
public byte[] image;
//constructor
public MyImagesEntity(String image_title, String image_description, byte[] image) {
this.image_title = image_title;
this.image_description = image_description;
this.image = image;
}
}
The @Dao annotated interface
@Dao
public interface MyImagesDao {
@Insert
void insert(MyImagesEntity myImagesEntity);
@Delete
void delete(MyImagesEntity myImagesEntity);
@Update
void update(MyImagesEntity myImagesEntity);
@Query("SELECT * FROM my_images ORDER BY image_id ASC")
LiveData<List<MyImagesEntity>> getAllImages();
}
The dependencies
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
def lifecycle_version = "2.5.0-alpha03"
// ViewModel
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
// LiveData
implementation "androidx.lifecycle:lifecycle-livedata:$lifecycle_version"
// Annotation processor
annotationProcessor "androidx.lifecycle:lifecycle-compiler:$lifecycle_version"
