我設置Backendless的應用程序,與具有行名稱posts
,其爲User
和Post
表之間的數據對象的關係,數據關係是1對多User
表。當我嘗試使用BackendlessUser.getProperty("key")
來檢索它時,它會返回零個對象。一旦它甚至返回HashMap
。我使用docs中提到的方式,但因爲Object[]
的大小爲零而變爲空。我肯定在那一行有數據,寫爲<uses-permission>
的互聯網。獲得從零個BackendlessUser的getProperty對象()
public class MainActivity extends AppCompatActivity {
BackendlessUser user = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Backendless.initApp(this, "app_id", "android_key", "v1");
Backendless.UserService.login("username", "password", new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
user = response;
doStuff();
}
@Override
public void handleFault(BackendlessFault fault) {
Log.e("Error logging in", "message: " + fault.getMessage());
}
});
}
//important
private void doStuff() {
Object[] postObjectArray = (Object[]) user.getProperty("posts");
Post[] posts = null;
if (postObjectArray != null && postObjectArray.length > 0)
posts = (Post[])postObjectArray;
if (posts == null)
{
Log.d("Problems", "posts is null");
}
}
}
Post
類:
public class Post extends Object{
private BackendlessUser user;
private String file;
private String message;
private String objectId;
public String getObjectId() {
return objectId;
}
public void setObjectId(String objectId) {
this.objectId = objectId;
}
public Post() {
}
public Post(BackendlessUser user, String file, String message) {
this.user = user;
this.file = file;
this.message = message;
}
public BackendlessUser getUser() {
return user;
}
public void setUser(BackendlessUser user) {
this.user = user;
}
public String getFile() {
return file;
}
public void setFile(String file) {
this.file = file;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}