4

I am trying to use the library DBFlow in Android. I have used it before and in the older version (2.2.1) it used a $Table.field. Now it seems to have another format where we reference a new class by "_Table".

Example:

int taxBracketCount = SQLite.select(count(Employee_Table.name))
.from(Employee.class)
.where(Employee_Table.salary.lessThan(150000))
.and(Employee_Table.salary.greaterThan(80000))
.count();

Where and when are these "_Table" classes created? How do I access them? (Even if I wanted to use and older version, my newly created studio project do not create the $ files either. Some explaination of this, or both, would be nice)

Yokich
  • 1,247
  • 1
  • 17
  • 31

5 Answers5

4

You need to run a successful build for the files to be generated. Make sure your code can compile, so remove any references to the "_Table" classes and run your project first and then you should be able to access them.

user1809913
  • 1,785
  • 1
  • 14
  • 25
2

I got weird errors recently as below, said it couldn't find those "$Table" classes, but actually they had been built and in there.

I commented and uncommented every new java files. And eventually I found that's because there is no "@PrimaryKey" in one model class of DBFlow.

So, you have to define the bloody "@PrimaryKey" for your DBFlow model classes( and don't forget to extends BaseModel as well). PS: DBFlow Version 3.0.0-beta

/Users/XXX/code_projects/###/src/main/java/com/XXXXX.java:9: error: cannot find symbol
import com.XXX.databasemodel.XXX$Table
Jagger
  • 2,352
  • 2
  • 13
  • 12
2

_Table classes and their corresponding methods to communicate with the database are created when you build your project. You can build it even with these errors, and they'll be created on that moment.

If you're still facing the issue, make sure you're adding the @Table annotation on top of your class, else they won't be created.

ZShock
  • 255
  • 3
  • 12
1

I have faced the same problem, but the reason was an absence of the annotation

@Table(databaseName = AppDatabase.NAME)

at the top of

public class AwesomeModel extends BaseModel 
    @PrimaryKey(autoincrement = false)
    @Column @Expose long id;

    public long getId() {
        return id;
    }
}

class...

isabsent
  • 3,683
  • 3
  • 25
  • 46
1

Ok so I was also facing similar issue -

And like someone else has also pointed out, the app needs to build to solve this. But removing all _table references first and removing them is a long task. I followed following steps -

  1. try to rebuild the app, it will fail
  2. Now head over to Problems tab in Android Studio
  3. Try to identify any issues other than _table - fix that issue and build again - voila!