Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

this is the error code

C:\Users\huh\AndroidStudioProjects\test\app\build\generated\ap_generated_sources\debug\out\com\name\test\database\AppDatabase_Impl.java:56: error: onCreate(SupportSQLiteDatabase) in <anonymous com.droidbane.test.database.AppDatabase_Impl$1> cannot override onCreate(SupportSQLiteDatabase) in Delegate
      protected void onCreate(SupportSQLiteDatabase _db) {
  attempting to assign weaker access privileges; was public

Can you at least share my mistake or your Room code that you used or could give an example?

this is my error code and it leads me here: (AppDatabase_Impl.java)

@Override
  protected void onCreate(SupportSQLiteDatabase _db) {
    if (mCallbacks != null) {
      for (int _i = 0, _size = mCallbacks.size(); _i < _size; _i++) {
        mCallbacks.get(_i).onCreate(_db);

This is the list I followed

folder layout

📦com.name.test
 ┣ 📂database
 ┃ ┗ 📜AppDatabase.java
 ┃ ┗ 📜Words.java
 ┃ ┗ 📜WordsDao.java
 ┣ 📜MainActivity.java

AppDataBase.java

 package com.name.test.database;
    import androidx.room.Database;
    import androidx.room.RoomDatabase;
    @Database(entities = {Words.class}, version = 1)
    public abstract class AppDatabase extends RoomDatabase {
        public abstract WordsDao wordsDao();

Words

package com.name.test.database;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity
public class Words {
    @PrimaryKey
    public int uid;
    @ColumnInfo(name = "words")
    public String words;

WordsDao

package com.name.test.database;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
public interface WordsDao {
    @Query("SELECT * FROM words")
    List<Words> getAll();
    @Insert
    void insertAll(Words... words);
    @Delete
    void delete(Words words);

MainActivity

package com.name.test;
import androidx.appcompat.app.AppCompatActivity;
import androidx.room.Room;
import android.nfc.Tag;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import com.droidbane.test.database.AppDatabase;
import com.droidbane.test.database.Words;
import com.droidbane.test.database.WordsDao;
import java.util.List;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    public void ChangeTextClick(View view) {
        AppDatabase db = Room.databaseBuilder(getApplicationContext(),
                AppDatabase.class, "database-name").build();
        WordsDao wordsDao = db.wordsDao();
        List<Words> words = wordsDao.getAll();
        Log.w("asd", "ChangeTextClick: " + words);

Is this error caused by me or is it due to the document? Are the codes old? Did I do something wrong?

I solved my problem by decreasing the version:

implementation 'androidx.room:room-runtime:2.2.2'
annotationProcessor "android.arch.persistence.room:compiler:1.1.1"
kapt "android.arch.persistence.room:compiler:1.1.1"
kapt 'androidx.room:room-compiler:2.2.2'
// optional - RxJava2 support for Room
implementation 'androidx.room:room-rxjava2:2.2.2'
// optional - RxJava3 support for Room
implementation 'androidx.room:room-rxjava3:2.4.2'
// optional - Guava support for Room, including Optional and ListenableFuture
implementation 'androidx.room:room-guava:2.2.2'
// optional - Test helpers
testImplementation 'androidx.room:room-testing:2.2.2'
// optional - Paging 3 Integration
implementation 'androidx.room:room-paging:2.4.2'
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.