android中ormlite中日期和时间对象的问题
我正在使用 ORMlite 将日期存储在 android 的 sqlite 中。我为数据创建了一个 POJO 类 当我为时间对象或日期对象创建成员变量时,它给出了 NullPointerException。
这是我的 Pojo 类
@DatabaseTable(tableName="user_prior_commitment")
public class PreferencesPriorCommitmentRowData {
// id is generated by the database and set on the object automagically
@DatabaseField(generatedId = true)
int id;
@DatabaseField(index = true)
int user_id;
@DatabaseField
String description;
@DatabaseField
String location;
@DatabaseField
Date date;
@DatabaseField
String start_time;
@DatabaseField
String end_time;
@DatabaseField
int lattitude;
@DatabaseField
int longitude;
...
,我用这个表手动创建了数据库 在我的活动中,我使用下面的代码
DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
DatabaseHelper db = manager.getHelper(context);
Dao<PreferencesPriorCommitmentRowData, Integer> simpleDao =
db.getPreferencesPriordataDao();
List<PreferencesPriorCommitmentRowData>aa = simpleDao.queryForAll();
,但在最后一行之前它给出了空指针异常。
请就此提供帮助。
I'm using ORMlite to store the date in sqlite in android. I've created a POJO class for Data
and when i'm creating a member variable for the Time object or Date Object it is giving NullPointerException.
this is my Pojo class
@DatabaseTable(tableName="user_prior_commitment")
public class PreferencesPriorCommitmentRowData {
// id is generated by the database and set on the object automagically
@DatabaseField(generatedId = true)
int id;
@DatabaseField(index = true)
int user_id;
@DatabaseField
String description;
@DatabaseField
String location;
@DatabaseField
Date date;
@DatabaseField
String start_time;
@DatabaseField
String end_time;
@DatabaseField
int lattitude;
@DatabaseField
int longitude;
...
And manually i created the database with this table
and in my activity i use the below code
DatabaseManager<DatabaseHelper> manager = new DatabaseManager<DatabaseHelper>();
DatabaseHelper db = manager.getHelper(context);
Dao<PreferencesPriorCommitmentRowData, Integer> simpleDao =
db.getPreferencesPriordataDao();
List<PreferencesPriorCommitmentRowData>aa = simpleDao.queryForAll();
But before the last line it it giving Null Pointer Exception.
Kindly Help regarding this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
java.util.Date
类型应映射到数据库中相应的DATETIME
类型。我认为这应该可以解决你的问题。A
java.util.Date
type should map to a correspondingDATETIME
type in the database. I think that should solve your problem.