我正在使用解析器在POST中创建用户类,并在我的仪表板上查看它。 当我尝试查询所有这些对象时,它会返回确切的对象数,但所有字段都为null或0。
ParseQuery<User> query = ParseQuery.getQuery(PARSE_USER);
query.findInBackground(new FindCallback<User>() {
@Override
public void done(List<User> list, com.parse.ParseException e) {
if (e == null) {
for (User user : list) {
Log.v("user:", user.toString());
}
//mListView.setAdapter(new LoveBoardAdapter(mCtx, list));
} else {
Toast.makeText(mCtx, getString(R.string.internet_error), Toast.LENGTH_LONG).show();
}
}
});
编辑:
这是常量,我的User.class
private final String PARSE_USER = "User";
@ParseClassName("User")
public class User extends ParseObject {
private int age;
private String name;
private String gender;
private String contact;
private String bio;
private String city;
private int likes;
public User() {
super();
}
public User(int age, String name, String gender, String contact, String bio, String city, int likes) {
this.age = age;
this.name = name;
this.gender = gender;
this.contact = contact;
this.bio = bio;
this.city = city;
this.likes = likes;
}
public int getLikes() {
return likes;
}
public void setLikes(int likes) {
this.likes = likes;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public String getBio() {
return bio;
}
public void setBio(String bio) {
this.bio = bio;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "User{" +
"age=" + age +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", contact='" + contact + '\'' +
", bio='" + bio + '\'' +
", city='" + city + '\'' +
", likes=" + likes +
'}';
}
}
答案 0 :(得分:2)
我的笔记:
使用以下代码进行测试, UserData类:
@ParseClassName("UserData")
public class UserData extends ParseObject {
// Setup the constant for the column names here
public static final String name = "name";
public static final String city = "city";
// :
public UserData() {
}
public String getName() {
// Get data using ParseObject
return getString(UserData.name);
}
public void setName(String newName) {
// Store data using ParseObject
put(UserData.name, newName);
}
// More setters and getters
// :
}
ShowUsers活动:
public class ShowUsers extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_users);
ParseQuery<UserData> query = ParseQuery.getQuery(UserData.class);
query.findInBackground(new FindCallback<UserData>() {
@Override
public void done(List<UserData> objects, ParseException e) {
if (e == null) {
for (UserData userData : objects) {
// Access with getter
Log.v("user name:", userData.getName());
// Access with type safe constant
Log.v("city: ", userData.getString(UserData.city));
}
}
}
});
}
}
答案 1 :(得分:1)
由于它是默认用户表,因此请更改:
ParseQuery<User> query = ParseQuery.getQuery(PARSE_USER);
query.findInBackground(new FindCallback<User>() {
@Override
public void done(List<User> list, com.parse.ParseException e) {
if (e == null) {
for (User user : list) {
Log.v("user:", user.toString());
}
//mListView.setAdapter(new LoveBoardAdapter(mCtx, list));
} else {
Toast.makeText(mCtx, getString(R.string.internet_error), Toast.LENGTH_LONG).show();
}
}
});
要
ParseQuery<ParseUser> query = ParseUser.getQuery();
query.findInBackground(new FindCallback<User>() {
@Override
public void done(List<ParseUser> list, ParseException e) {
if (e == null) {
for (User user : list) {
Log.v("user:", user.toString());
}
//mListView.setAdapter(new LoveBoardAdapter(mCtx, list));
} else {
Toast.makeText(mCtx, getString(R.string.internet_error), Toast.LENGTH_LONG).show();
}
}
});
答案 2 :(得分:0)
尝试从
更改@ParseClassName("User")
到
@ParseClassName("_User")