gpt4 book ai didi

java - 在 android 中检索 ParseUser 对象时遇到问题

转载 作者:行者123 更新时间:2023-12-01 10:46:59 24 4
gpt4 key购买 nike

您好,我是新来解析并成功创建友谊表的。现在我正在尝试检索已请求与 ParseUser B 成为 friend 的 Parseuser A。但我收到一条错误消息 java.lang.IllegalStateException: ParseObject has no data for 'username'. Call fetchIfNeeded() to get the data.基本上,我检索请求者信息并尝试在 ListView 中显示,因为用户可以决定拒绝或接受友谊。请有人告诉我我做错了什么。我只想在发送添加 friend 的请求时显示请求者信息。然后 userB 可以选择接受或拒绝该请求。

private void queryFriendShipRequest() {
//retrieving requesters info to display on a list view
ParseQuery<ParseObject> parseQuery = ParseQuery.getQuery("Friendship");
parseQuery.whereEqualTo("accepterId", ParseUser.getCurrentUser());
parseQuery.whereEqualTo("Status", "pending");
parseQuery.findInBackground(new FindCallback<ParseObject>() {
@Override
public void done(List<ParseObject> objects, ParseException e) {
if (e == null) {
parseUserList.clear();
for (ParseObject parseObject : objects) {
parseUserList.add((FriendShip) parseObject);
// Log.d("FriendShip", parseUserList.toString());
}
updateFriendsList();
}
else {
Log.d(TAG, "Unable to retreive Invites: " + e.getMessage());
}

}
});
}

private void updateFriendsList() {

ArrayAdapter adapter = new ArrayAdapter(getActivity(), R.layout.friend_request_list, parseUserList) {

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// return super.getView(position, convertView, parent);
if(convertView==null) {
convertView = getActivity().getLayoutInflater().inflate(R.layout.friend_request_list, parent, false);
}

ProfilePictureView profilePictureView1 = (ProfilePictureView)convertView.findViewById(R.id.userProfileName11);
TextView textView = (TextView)convertView.findViewById(R.id.IDNameOfPerson);
Button button = (Button)convertView.findViewById(R.id.accept);
Button button1 = (Button)convertView.findViewById(R.id.reject);
profilePictureView1.setProfileId(parseUserList.get(position).getFrom().getString("UserId); //errors complaining it cannot retrieve parseuser
textView.setText(parseUserList.get(position).getFrom().getUsername()); //errors complaining it cannot retrieve parseuser

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
acceptFriendRequest(position);
}
});

button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//rejectFriendRequest(position);
}
});

return convertView;
}

};
friendsList.setAdapter(adapter);
}

我的错误:

12-06 17:26:20.236  18468-18468/com.example.davchen.skibuddies E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.davchen.skibuddies, PID: 18468
java.lang.IllegalStateException: ParseObject has no data for 'username'. Call fetchIfNeeded() to get the data.
at com.parse.ParseObject.checkGetAccess(ParseObject.java:3513)
at com.parse.ParseObject.getString(ParseObject.java:3089)
at com.parse.ParseUser.getUsername(ParseUser.java:373)
at com.example.davchen.skibuddies.Fragments.ProfileTab$2.getView(ProfileTab.java:114)
at android.widget.AbsListView.obtainView(AbsListView.java:2823)
at android.widget.ListView.measureHeightOfChildren(ListView.java:1290)
at android.widget.ListView.onMeasure(ListView.java:1202)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1489)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.support.v7.internal.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:124)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1435)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:721)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:612)
at android.view.View.measure(View.java:18596)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5827)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:430)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2897)
at android.view.View.measure(View.java:18596)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2248)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1306)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1548)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777)
at android.view.Choreographer.doCallbacks(Choreographer.java:590)
at android.view.Choreographer.doFrame(Choreographer.java:560)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:763)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5942)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

最佳答案

解决了。我所要做的就是使用 include 来访问 requesterId。

query.include("requesterId");

关于java - 在 android 中检索 ParseUser 对象时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34125202/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com