DBFlow icon indicating copy to clipboard operation
DBFlow copied to clipboard

[3.0.0-beta1]Table is not registered with a Database. Did you forget the @Table annotation?

Open KChernenko opened this issue 10 years ago • 35 comments

But I have the folowing structure:

@Database(name = WeatherDB.NAME, version = WeatherDB.VERSION)
public class WeatherDB {

    public static final String NAME = "Weather";

    public static final int VERSION = 1;
}

And table:

@Table(database = WeatherDB.class)
public class WeatherTable extends BaseModel {

    @Column
    @PrimaryKey
    private long dateStamp;
    @Column
    private double dayTemperature;
    @Column
    private double minTemperature;
    @Column
    private double maxTemperature;
    @Column
    private double nightTemperature;
    @Column
    private double eveTemperature;
    @Column
    private double mornTemperature;
    @Column
    private int humidity;
    @Column
    private String description;
    @Column
    private double windSpeed;

   //getters and setters
}

Full stacktrace:

Process: me.bitfrom.weatherapp, PID: 3939
                                                                     com.raizlabs.android.dbflow.structure.InvalidDBConfiguration: Table: me.bitfrom.weatherapp.database.WeatherTable is not registered with a Database. Did you forget the @Table annotation?
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getDatabaseForTable(FlowManager.java:109)
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getModelAdapter(FlowManager.java:271)
                                                                         at com.raizlabs.android.dbflow.config.FlowManager.getTableName(FlowManager.java:68)
                                                                         at com.raizlabs.android.dbflow.sql.language.From.<init>(From.java:55)
                                                                         at com.raizlabs.android.dbflow.sql.language.Select.from(Select.java:58)
                                                                         at me.bitfrom.weatherapp.ui.fragments.TodaysWeatherFragment.onViewCreated(TodaysWeatherFragment.java:31)
                                                                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:908)
                                                                         at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1067)
                                                                         at android.app.BackStackRecord.run(BackStackRecord.java:834)
                                                                         at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1452)
                                                                         at android.app.FragmentManagerImpl$1.run(FragmentManager.java:447)
                                                                         at android.os.Handler.handleCallback(Handler.java:739)
                                                                         at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                         at android.os.Looper.loop(Looper.java:211)
                                                                         at android.app.ActivityThread.main(ActivityThread.java:5389)
                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                         at java.lang.reflect.Method.invoke(Method.java:372)
                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1020)
                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:815)

KChernenko avatar Dec 28 '15 01:12 KChernenko

I have the same problem

MaciejCzekanski avatar Dec 29 '15 23:12 MaciejCzekanski

@MaciejCzekanski are you using Dagger 2 in your project?

KChernenko avatar Jan 01 '16 13:01 KChernenko

@KChernenko Yes, I can't make them both work at the same time. Do you have any solution?

MaciejCzekanski avatar Jan 01 '16 15:01 MaciejCzekanski

Are you using proguard? If so, this config might help (solved the issue in our case)

-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }

simplysoft avatar Jan 03 '16 00:01 simplysoft

@simplysoft unfortunatelly proguard is disabled. I think it doesn't work in our case (mine and @MaciejCzekanski 's) because of Dagger 2.

KChernenko avatar Jan 03 '16 14:01 KChernenko

Yes, I don't use Proguard. I'm not sure what I've changed, but now I get compile-time error, that Dagger's Component class is missing. When I remove @Table annotation then it compiles, but obviously crashes at runtime with error "Table is not registered with a Database".

MaciejCzekanski avatar Jan 03 '16 18:01 MaciejCzekanski

@MaciejCzekanski have the same problem. Lets mark @agrosner here to infrom.

KChernenko avatar Jan 04 '16 19:01 KChernenko

There are issues with annotation processors and how order can matter. Dagger2 has some issues with that, and unfortunately I do not know of a solution of how to fix that

agrosner avatar Jan 10 '16 03:01 agrosner

This same error is almost making me now think of an alternative ORM

amugox avatar Jan 10 '16 11:01 amugox

Finally it works for me! I had forgotten to add the Application class on the manifest

<application android:name=".App.TotoApp":

amugox avatar Jan 10 '16 18:01 amugox

@amugox I have Application class referenced in manifest and it doesn't work. Do you also use Dagger 2?

MaciejCzekanski avatar Jan 10 '16 20:01 MaciejCzekanski

I am getting same error using Dagger 2 =/

epool avatar Jan 15 '16 18:01 epool

I'm getting the same error but just on one of my project, with the exact same database configuration, the one working is the android-testing project.

And I'm not using Dagger 2 :-1: :cry:

Ekt0s avatar Jan 26 '16 11:01 Ekt0s

A workaround I am using to face this in my development process is doing Build -> Build Project and then run it again. =/

epool avatar Jan 26 '16 15:01 epool

are you guys using 2.0.0+ of the Gradle plugin with instant run enabled?

agrosner avatar Jan 26 '16 17:01 agrosner

Yes, I am using classpath 'com.android.tools.build:gradle:2.0.0-alpha7' with instant run enabled.

epool avatar Jan 26 '16 18:01 epool

Im 95% sure its an instant run bug.

agrosner avatar Jan 26 '16 20:01 agrosner

+1 ProGuard rule fixed things for me. I suggest it be added a consumer proguard rule for the library?

-keep class * extends com.raizlabs.android.dbflow.config.DatabaseHolder { *; }

rogerhu avatar Feb 01 '16 07:02 rogerhu

Hi all

We are having the same problem here, in instrumented unit tests. I am using Dagger 1.2.2 and the build tools are version 1.5.0.

I have an abstract test case that injects the dependencias using dagger:

public abstract class FlowTestCase extends InstrumentationTestCase {

    ObjectGraph objectGraph;

    public FlowTestCase() {
        FlowLog.setMinimumLoggingLevel(FlowLog.Level.I);
    }

    protected void setUp(){
        objectGraph = ObjectGraph.create(new AndroidTestModule(getInstrumentation().getContext())).plus(getModules().toArray());
        objectGraph.inject(this);
    }

But I get the error while trying to delete the tables in the setUp in each test:

@RunWith(AndroidJUnit4.class)
public class ExampleTest extends FlowTestCase {

    @Inject
    LocalDataManager localDataManager;

    @Override
    protected List<Object> getModules() {
        return new ArrayList<>();
    }

    @Before
    public void setUp() {
        super.setUp();
        Delete.tables(MyTable.class);
    }

    @After
    public void tearDown() {
        Delete.tables(MyTable.class);
    }

The injected LocalDataManager executes the FlowManager.init(context);

jesdiart avatar Feb 02 '16 16:02 jesdiart

I can confirm that this issue is caused by instant run. I disabled it and it fixed the issue.

viethoang88 avatar Feb 03 '16 00:02 viethoang88