0

我正在关注https://github.com/pardom/ActiveAndroid/wiki/Querying-the-database将 activeandroid 合并到我的应用程序中,如下所示:

@Table(name="Contact")
public class Contact extends Model implements Serializable, Comparable {

public Contact() {
    super();
}


public Contact(String id, String n, String c, String p, String addr, String phone,     
String fb, String twit, String yt) {
    super();
    candID = id;
    name = n;
    chamber = c;
    party = p;
    address = addr;
    phoneNo = phone;
    facebook = fb;
    twitter = twit;
    youtube = yt;
}

public static List<Contact> getCachedContactsByState(String stateAbbr) {
    /*return new Select().from(Contact.class).where("state = ?",
                                                  stateAbbr).execute();*/
    Select s = new Select();
    From f = s.from(Contact.class);
    f = f.where("state = ?", stateAbbr);
    List<Contact> cachedContacts = f.execute();

    return cachedContacts;
}

根据我的调试器, f.execute 抛出一个空指针异常,并且 f 不为空。

只是确保,教程没有提到在使用activeandroid之前需要安装sqlite,它说activeandroid的目的是使用对象及其函数在sqlite上进行CRUD,所以我假设我只需要按照教程创建和查询我的 sqlite 数据库?

4

1 回答 1

1

看起来您忘记ActiveAndroid.initialize()使用有效的Context. 请参阅您链接到的文档中的入门部分。

于 2014-09-19T20:03:19.270 回答