sekula87
sekula87

Reputation: 357

Executing a custom query using the ORMLite query builder

I read all documentation about orm lite, also looking on net but didn't find right answers. I want to execute this statement:

SELECT * from Drive where day_number=150;

I have class that represent table:

@DatabaseTable(tableName="Drive")
public class Drive{

    @DatabaseField(generatedId=true)
    private int drive_id;

    @DatabaseField
    private String start_time;

    @DatabaseField
    private String end_time;

    @DatabaseField
    private String price;

    @DatabaseField
    private String distance;

    @DatabaseField
    private String day_number;

    @DatabaseField
    private String week_number;

    @DatabaseField
    private String month;

    getters and setters ...
}

When i run:

List<Drive> today = getHelper().getVoznjaDao().queryBuilder().where().
        eq("day_number","150").query();

I get NullPointerExeption, and it's not because there is no record for 150 in database. Please help i am desperate.

Upvotes: 0

Views: 4358

Answers (1)

Gray
Gray

Reputation: 116908

Your code looks fine in terms of the query-builder logic. I suspect that something to do with your wiring is incorrect however. In your comments you mention that the NPE happens on the query line.

List<Drive> today = getHelper().getVoznjaDao().queryBuilder().where().
    eq("day_number","150").query();

Most likely this means that either:

  • getHelper() is returning a null helper instance
  • getVoznjaDao() is returning a null DAO
  • or there are bugs in ORMLite

today being null would not cause a NPE since it is not dereferenced on the line. Certainly a bug in ORMLite is not out of the question but I would first check with a debugger to see if the getHelper() or getVoznjaDao() calls are returning null. I suspect you will find the bug at that point.

Upvotes: 1

Related Questions