我正在尝试使用此查询从azure移动服务中检索数据。但它不起作用,我确信它们是数据库中的数据。
userTable.where().field("id").eq(1).execute(new TableQueryCallback<User>() {
@Override
public void onCompleted(List<User> users, int i, Exception e, ServiceFilterResponse serviceFilterResponse) {
这是我初始化MobileServiceClient的方式。
try
{
mClient = new MobileServiceClient(getString(R.string.azure_site),getString(R.string.azure_key),this);
mClient.setGsonBuilder(new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES));
mClient.registerSerializer(ArrayList.class,new CollectionSerializer<Object>());
}
catch (MalformedURLException e)
{
AppMsg.makeText(this, getString(R.string.service_error), AppMsg.STYLE_ALERT).show();
}
这是我的用户模型。
public class User
{
private int id;
private String facebookId;
private String firstname;
private String lastname;
private ArrayList<Alarm> alarms;
private ArrayList<Moment> moments;
private ArrayList<User> bannedUsers;
private String channel;
public String getRegistrationId() {
return channel;
}
public final void setRegistrationId(String registrationId) {
channel = registrationId;
}
public User()
{
}
public User(int userId,String facebookId,String firstname,String lastname,ArrayList<Alarm> alarms,ArrayList<Moment> moments,ArrayList<User> bannedUsers)
{
//this.moments = moments;
this.alarms = alarms;
this.id = userId;
this.facebookId = facebookId;
this.firstname = firstname;
this.lastname = lastname;
this.bannedUsers = bannedUsers;
}
/**
* Getters and setters
*
*/
public String getFirstname() {
return firstname;
}
public final void setFirstname(String firstname) {
this.firstname = firstname;
}
public int getId() {
return id;
}
public final void setId(int id) {
this.id = id;
}
public String getLastname() {
return lastname;
}
public final void setLastname(String lastname) {
this.lastname = lastname;
}
@Override
public boolean equals(Object o) {
return o instanceof User && ((User) o).id == id;
}
public String getFacebookId() {
return facebookId;
}
public void setFacebookId(String facebookId) {
this.facebookId = facebookId;
}
public ArrayList<Alarm> getAlarms() {
return alarms;
}
public void setAlarms(ArrayList<Alarm> alarms) {
this.alarms= alarms;
}
public ArrayList<Moment> getMoments() {
return moments;
}
public void setHistory(ArrayList<Moment> moments) {
this.moments = moments;
}
public ArrayList<User> getBannedUsers() {
return bannedUsers;
}
public void setBannedUsers(ArrayList<User> bannedUsers) {
this.bannedUsers = bannedUsers;
}
}
数据库中存在数据。(这是测试数据。)
我真的不确定导致问题的原因。我没有收到错误消息,当我在onComplete回调中收到数组时,只是一个null。
要指出的事情。
答案 0 :(得分:0)
您是否尝试删除该表并重新创建它?有些东西可能出错,导致表格在读取时无法正常工作。